How to sop a winning trade from reopening again for a bit

 

Hello,


I have a function that opena a trade on signal idicators, but after it closes out of the trade it opens another one up again.

I'm wondering how to write a function that would would wait a half hour before it can open another one.


Code is

 if (!ExistPositions()){

      if ((Buy1=Buy2)){

         OpenBuy();

         return;

      }

What can I add to this function to make it work that way?


Thanks

 
Tuck99:

Hello,


I have a function that opena a trade on signal idicators, but after it closes out of the trade it opens another one up again.

I'm wondering how to write a function that would would wait a half hour before it can open another one.


Code is

 if (!ExistPositions()){

      if ((Buy1=Buy2)){

         OpenBuy();

         return;

      }

What can I add to this function to make it work that way?


Thanks

First, you put this guy before OnInit() (make it general statement)

int TimeHold = 0;


then change your current code to the following. Vuala! Now your trade will open once per hour. Goodluck.

if(!ExistPositions()) {     if ((Buy1=Buy2) && TimeHold != Hour())     {         OpenBuy();         TimeHold = Hour();         return;     } }

 
You also, can check exists positions (for example, how near they are placed to the current price).
 
Ahmad Zuhairdi Noh:

First, you put this guy before OnInit() (make it general statement)

int TimeHold = 0;


then change your current code to the following. Vuala! Now your trade will open once per hour. Goodluck.

Thanks. So, you mean after the first trade closes out, then it will wait an hour even if a buy order is sent to it before the hour is up?

Reason: