Order on every tic

 

I am new to coding and do need help badly. i was able to write a code to open market order but found out it opens new order on every tick, how can i limit the open order to only the first opened one when condition is met. Anyone with guidance will be appreciated. thanks

 

There's lots of ways to do this.

Once per Condition met.

Once per Bar.

Once per Order(s).

Once per Hour/Day.

Etc...Etc

It depends on your code logic. Which ones are important to your strategy?

 
ubzen:

There's lots of ways to do this.

Once per Condition met.

Once per Bar.

Once per Order(s).

Once per Hour/Day.

Etc...Etc

It depends on your code logic. Which ones are important to your strategy?


i think once per contition met. thanks for you prompt response.
 
okanski:

i think once per contition met. thanks for you prompt response.
Yeah but the condition is met on every tick. So you need some more filters. Or decide how often you want to place the order. Example you can turn the trading off when the first order is set. But when do you want it to resume trading again. When OrdersTotal become Zero? Or what?
 
ubzen:
Yeah but the condition is met on every tick. So you need some more filters. Or decide how often you want to place the order.

let me describe, i want one buy order open as condiition is met, then the e.a goes into a rest till sell conditions are met and a sell order is opened, then it goes into rest till buy conditions are met and repeat
 

So a Reverse. Well simple way I did it when I was new is to use a Global or Static Variable.

Example:

int Last_Direction; //Global Variable Above Start.

if( Buy_Condition == true){
    if( Last_Direction == 0 || Last_Direction== -1){
        if(OrderSend( Buy )>-1 ){ Last_Direction= 1;}
    }
}

if( Sell_Condition == true){
    if( Last_Direction == 0 || Last_Direction==  1){
        if(OrderSend( Sell )>-1){ Last_Direction=-1;}
    }
}
As you get better, you want to search for the order and it's order type. 0 vs 1;
 
ubzen:

So a Reverse. Well simple way I did it when I was new is to use a Global or Static Variable.

Example:

As you get better, you want to search for the order and it's order type. 0 vs 1;


ubzen, thanks a lot, youve been great, will look into your suggestion and see how it goes.
 
okanski:

ubzen, thanks a lot, youve been great, will look into your suggestion and see how it goes.

Cool.
Reason: