How to save value for future

 

Hello,


I have some problems to use several criterias for market operations.

For example, for selling:

1) First I want price to reach some resistance level (red line)

2) Second, I need to wait for market to broke under some lower level.

I don't want to use OrderSend with limited time, as I need more criteria to be fulfilled in case of Order Sending (for example some level of Macd at sending Order).

What kind of variable or sentence construction should I use ?

Below is example of some code. However isResistance don't save its value at next bar (despite I declare it before Start() function)


Thanks,

Edvard

bool isResistance;

if (High > ResistanceLevel)  //if high is higher than earlier 200 bars in chart
   isResistance = true;
   
if (isResistance)
   if (Macd < MacdMaxLevel)   
      if (Close[1] < LowerLevel)
         OrderSend(Symbol(), ... , OP_SELL, .....)
 
edas:

Below is example of some code. However isResistance don't save its value at next bar (despite I declare it before Start() function)

If you defined isResistance outside of start and init then it should be globally defined . . .

 

Puzzling. If isResistance is declared globally, and it gets set as true, then it will stay true until it is set to false. Try finding out whether it whether it does become true, and when it becomes false (if this does happen). (You could add code to log the time when it changes to false).

 

Yes, I declared variable isResistance globally (atter external variables). If it's value is assigned "true" by assignment (by conditions), arrow is drawn on the bar.

conditions:


if (High[1] > ResistLevel && Close[1] < ResistLevel)
     isResistance = true;



However if High[1] is lower than ResistLevel,

isResistance becomes "false" without assignment to "false"

Should it be that way ?

 
edas:

However if High[1] is lower than ResistLevel,

isResistance becomes "false" without assignment to "false"

Should it be that way ?

I don't believe that is the case or even possible . . . show your code or just look for it yourself, try searching using Ctrl + F in the editor . . .
 
RaptorUK:
I don't believe that is the case or even possible . . . show your code or just look for it yourself, try searching using Ctrl + F in the editor . . .

Yes, I find where error was. Thanks for help !


Edward

 
edas:

Yes, I find where error was. Thanks for help !


Well done :-) you are welcome.
 
// need to set to  false
if (High[1] > ResistLevel && Close[1] < ResistLevel)
     isResistance = true;

/////////////// or just
     isResistance = (High[1] > ResistLevel && Close[1] < ResistLevel);