Then use different Magic#. Example. Edit* Order select loop no longer need. Because it'll be included within the custom function.
if(Count_Order_With_Symbol_And_Magic( Chart_A_Symbol, Chart_A_Magic )==1 && Count_Order_With_Symbol_And_Magic( Chart_B_Symbol, Chart_B_Magic )==0 <-Custom Function ){ OrderSend( Chart_B_Symbol, Chart_B_Magic ); }
About hedging tactics, I must point out what I experienced when trying to test such strategies.
I've a demo account with IBFX. They don't permit hedge trading e.g. if I place a buy order, and then a sell order on the same currency, or viceversa, I get a warning saying that hedge trading is not permitted.
Is that true in real? Does it depend on the particular broker used, or a general rule ?
Thank you
Then use different Magic#. Example. Edit* Order select loop no longer need. Because it'll be included within the custom function.
OK, thanks! I am trying to write this "Count_Order_With_Symbol_And_Magic" function, am I close?
extern string HedgedSYMBOL = "";
extern int HedgedMAGIC = 0;
int HedgedOrdersCount()
{
int HedgedOrdersCount = 0;
for (int i = OrdersTotal()-1; i >=0; i--)
if {(OrderSelect(i, SELECT_BY_POS, MODE_OPEN) && OrderSymbol() == HedgedSYMBOL && OrderMagicNumber() == HedgedMAGIC}
return(HedgedOrdersCount);
}
This . . .
int HedgedOrdersCount = 0; // <---- ! ! for (int i = OrdersTotal()-1; i >=0; i--) if {(OrderSelect(i, SELECT_BY_POS, MODE_OPEN) && OrderSymbol() == HedgedSYMBOL && OrderMagicNumber() == HedgedMAGIC} return(HedgedOrdersCount); // <---- ! !
. . . will always return 0
OK, thanks! I am trying to write this "Count_Order_With_Symbol_And_Magic" function, am I close?
Not a bad effort. Three problems (fixed below)
extern string HedgedSYMBOL = ""; extern int HedgedMAGIC = 0; int HedgedOrdersCount(){ int ordersCount = 0; for (int i = OrdersTotal()-1; i >=0; i--){ if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==HedgedSYMBOL && OrderMagicNumber()==HedgedMAGIC ){ ordersCount++; } } return( ordersCount ); }
1) When counting you have to remember to actually increment the counter
2) Don't call a variable by the same name as a function
3) In the OrderSelect function you have some random parameter (MODE_OPEN). Try reading the help on the function and use a valid parameter.
bruno:
I've a demo account with IBFX. They don't permit hedge trading e.g. if I place a buy order, and then a sell order on the same currency, or viceversa, I get a warning saying that hedge trading is not permitted.
Is that true in real? Does it depend on the particular broker used, or a general rule ?
This . . .
. . . will always return 0
Many thanks RaptorUK & dabbler ! it works just fine now!!! I really appreciate your detailed feedback and explanations, that was awesome.
I also added the bit below at the int start() stage to complete my initial logic, in case others may want to use this little tweak - feel free to suggest improvements (I guess this is rather "brute-force" but works just fine for my purposes).
bool enableopen;
if (HedgedOrdersCount()==1) {enableopen=true; addcomment ("Hedge Open ENABLED ");}
if (HedgedOrdersCount()<1) {enableopen=false; addcomment ("Hedge Open DISABLED ");}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello there,
I am currently using this simple hedging tactic, which implies entering oposite signal trades from one chart when certain things happen with an already open order in another (same symbol and timeframe). Is there anyway I can automate this? i.e. is there any way I can have a condition such as:
if (order in ChartA is open) then open order in ChartB
else (do nothing in ChartB)
I was thinking of some tweaks with counting orders and using the same magic numbers, but it cannot work as same magic# will messup the mechanics and logic. any other suggestions//?
Any feedback, most welcome!
Many thanks,
Dan.