Ok so i think i solved problem 1. Instead of doing this
int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SL1,Takeprofit,"My order",MAGICNUM,0,clrGreen);
i did this, like right after i posted this
int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SL1,TP+0.0024,"My order",MAGICNUM,0,clrGreen);
And that works perfectly. Now for the second problem...i have been doing some reading and i need to put in some loops or something. Or perhaps use my magic number? Can someone assist with the code
add extra condition to your code - count open orders:
if ((LastFastMA<LastSlowMA) &&(FastMA>SlowMA)) { double Takeprofit = TP+0.0024; double SL1 = SL-0.001; if(CountOrder(OP_BUY) == 0) { int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SL1,Takeprofit,"My order",MAGICNUM,0,clrGreen); if(ticket<0) Print("OrderSend failed with error #",GetLastError()); else Print("OrderSend placed successfully"); } } //+------------------------------------------------------------------+ int CountOrder(int Order_Type) { int orders=0; for(int i=OrdersTotal()-1;i>=0;i--){ if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false) continue; if(OrderSymbol()!=_Symbol || OrderMagicNumber() != MAGICNUM) continue; if(Order_Type == OrderType() || Order_Type == -1) orders++; } return(orders); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi All,
This is the first time im posting here as it's my first time doing ANY coding, i seriously didnt know anything about coding since 2 days ago. I must say, it's pretty fun. I have learned quite a bit by trial and error and reading the articles here. Anyways this bot is still a work in progress and my code looks like a mess, nevertheless i have a problem. if i put my TP on the line of code above my SL line of code then when my bot runs it only placed the trade with a TP; if i switch it around then the SL is put in when the order is placed but the TP is missing.
I am obviously doing something completely wrong so i would appreciate if someone can point me in the right direction. So what i did was to get the bid and ask price and then just add on from there so that its a certain amount of pips for TP and a certain amount of pips for SL bearing in mind the brokers minimum SL amount.
Then the other problem is that i just need some code that will stop a crap load of positions opening at the trigger. I just need 1 position opened when the cross happens unless its an opposite trigger
In short
1) SL and TP wont be placed in the order together
2) I need 1 trade opened per cross
Please help, i'm really new to this so im going to need a little explanation of why it doesn't work