In lieu of ticket: IF() statement problem

Hi,

OK. I will post my ticket here just to get something happening.

I am trying to do a simple peak-detector-with-reset (code below). There are 3 IF()s in the code. The code fails on the third IF() (the associated 'plot' variable disappears of the screen is the only symptom). There is self-referentiality in the 1st IF() that works fine. The code is accepted by the compiler as valid. There's nothing obviously wrong with the 3rd IF().

PRETRADE = SWITCH( ((NDTOT[1] <= 0.0) AND (NDTOT[0] > NDTOT[1])), NDTOT[0] < NDTOT[1]); BUY = PRETRADE[0] and (PRETRADE[1] <= 0); BUY_PRICE = if(BUY[1] > 0, open(), BUY_PRICE); ND = COUNTMATCHSINCESIGNAL( 1 , BUY); PROFIT = close() - BUY_PRICE; GO = if(ND <= 1, 1.000, close()/BUY_PRICE); Gad = 1.0 + (GO - 1)/ND; Gad_max = if(Gad > Gad_max, Gad, Gad_max);

I have tried to see if other functions in the language can do what I want. They don't seem to be useful for this, but maybe I've missed something. All I want is to capture and maintain the maximum in Gad (called Gad_max) and reset it when GO is reset to 1 (happens because of the BUY single-day pulse).

I can't see why the script doesn't work.

cheers

colin

(happy to issue a ticket on this if you want, when the system works)

Hi

Posting my code (a literal Ctrl-C of the Optuma code surrounded by

 and 
, I thought), has failed in the forum editor. Maybe that's the cause of the failure in the ticket system?

cheers

colin

 

Another test to post the real code:

PRETRADE = SWITCH( ((NDTOT[1] <= 0.0) AND (NDTOT[0] > NDTOT[1])), NDTOT[0] < NDTOT[1]); BUY = PRETRADE[0] and (PRETRADE[1] <= 0); BUY_PRICE = if(BUY[1] > 0, open(), BUY_PRICE); ND = COUNTMATCHSINCESIGNAL( 1 , BUY); PROFIT = close() - BUY_PRICE; GO = if(ND <= 1, 1.000, close()/BUY_PRICE); Gad = 1.0 + (GO - 1)/ND; Gad_max = if(Gad > Gad_max, Gad, Gad_max);

Hi Colin,

You mentioned in your other post that the issue had been resolved. I’m not sure what adjustment you made, but we had a look at the script and this is the adjustment we made to resolve it…

PRETRADE = SWITCH( ((NDTOT[1] <= 0) AND (NDTOT[0] > NDTOT[1])), NDTOT[0] < NDTOT[1]);
BUY = (PRETRADE > 0) and (PRETRADE[1] <= 0);
BUY_PRICE = if(BUY[1] > 0, open(), BUY_PRICE);
ND = COUNTMATCHSINCESIGNAL( 1 , BUY); 
PROFIT = close() - BUY_PRICE;
GO = if(ND <= 1, 1, close()/BUY_PRICE);
Gad = 1 + (GO - 1)/ND;
Gad_max = if((GO == 1) or (Gad >  Gad_max[1]   ), Gad,  Gad_max[1]);
Gad_max

The adjustments we made are on the last 2 lines of the script.