[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Need help with setting a variable to 1 if condition is matched otherwise set to 0



PureBytes Links

Trading Reference Links

Assume you want to check if the bars are exactly one minute apart, this will give 0 or 1 result
You just needed double equal sign for equality of values, not single

Current_Timenum=TimeNum();
Previous_Timenum=Ref(TimeNum(),-1);
Newbar_Difference=Current_Timenum-Previous_Timenum;
NewBar_Started = Newbar_Difference ==100;


Also you incorrectly used IIF and IF functions, IF is only suitable in loops, or if using static values (not arrays)
To write using IIF to get same as above, but the IIF is not required for straight 0 or 1 values
NewBar_Started = iif( Newbar_Difference ==100, 1, 0) ;

--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com

On 21/09/2007, Padhu <ccie8340@xxxxxxxxx> wrote:
Hello,
 
I have this into support as well...wondering if anyone can take a stab at this on the groups here.
 
Basically i want newbar_started to be set to 1 when Newbar_Difference=100 otherwise set to 0.  I would then like this NewBar_Started=1 to be ANDed inside if statement.
 Obviously I am missing something here, so the below code is not working.
 
Current_Timenum=TimeNum();
Previous_Timenum=Ref(TimeNum(),-1);
Newbar_Difference=Current_Timenum-Previous_Timenum;
Newbar_Difference_100=(Newbar_Difference =100);
"Newbar_Difference is "+Newbar_Difference;

if(( Newbar_Difference ==100) ) NewBar_Started = 1;
else if ( Newbar_Difference <>100 ) NewBar_Started = 0;
"NewBar_Started is "+NewBar_Started;

if(NewBar_Started=1 AND LastValue(Ref( Cover, -1) ) )

{

mvOrderOIF =

"1"+","+

Broker_Symbol+

","+ "BUYSTOP" +

","+ 2 +

","+ (High+Entry_Offset_For_ScalperTrades) +

","+ (Low-Stop_Offset_For_ScalperTrades) +

","+ (High+-EXIT_Offset_For_ScalperTrades) +

"," + ScalperSwing_BuyStrategy_Name;

thanks,Padhu



__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___