consider spreads and comission

consider spreads and comission

Manage alerts

Loading saved threads...

Ali Afkari · External communityPost link
External question — Stack Overflow Stack Exchange Author: Ali Afkari Original post: https://stackoverflow.com/questions/66406036 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. i want to code an EA that when open a Buy/Sell position with 60 point profit. if the position goes to -20 point profit then open a position In the opposite direction of first position with 60 point profit the code is hear: if(orderType==OP_BUY) ticket = OrderSend(Symbol(),orderType,lots,openPrice,5,stopLossPrice,takeProfitPrice,"AFKARIAUS ",MagicBuy,0,clrGreen); if(orderType==OP_SELL) ticket = OrderSend(Symbol(),orderType,lots,openPrice,5,stopLossPrice,takeProfitPrice,"AFKARIAUS ",MagicSell,0,clrGreen); for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicBuy && OrderType()==OP_BUY) BuyTicket=OrderSend(Symbol(),OP_SELLSTOP,lots,OrderOpenPrice()-20*Point,5,OrderOpenPrice()+60*Point,OrderOpenPrice()-20*Point-60*Point,"AFKARIAUS",MagicBuy+1,0,clrBlue); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicSell && OrderType()==OP_SELL) SellTicket=OrderSend(Symbol(),OP_BUYSTOP,lots,OrderOpenPrice()+20*Point,5,OrderOpenPrice()-60*Point,OrderOpenPrice()+20*Point+60*Point,"AFKARIAUS",MagicSell+1,0,clrBlue); } every thing is ok but when test with real money there is Comission,Spreads and Swap.and i dont know what should i do please help me thanks
Quote
Report
Pantelis Pap. · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Pantelis Pap. Original post: https://stackoverflow.com/a/66557402 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. A smart solution, that includes swap and commission is to do with that order: OrderSelect OrderSwap & OrderCommission (sum those) if (OrderSelect(ticket_number,SELECT_BY_TICKET,MODE_TRADES)==true) { current_trade_absolute_profit = OrderSwap() + OrderProfit() + OrderCommission(); } You can also find and store pip value like that: double tick_value = MarketInfo(Symbol(),MODE_TICKVALUE); Then calculate current pip prices and after that you can simply replace a double's value each time you earn more pips like that if (current_pip_number > highest_pip_number) { highest_pip_number = current_pip_number; } if (highest_pip_number < current_pip_number + 20) { OrderClose(ticket_number,lotsize,iClose(NULL,0,0),slippage,clrViolet); }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Ali Afkari Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/66406036 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. i want to code an EA that when open a Buy/Sell position with 60 point profit. if the position goes to -20 point profit then open a position In the opposite direction of first position with 60 point profit the code is hear: if(orderType==OP_BUY) ticket = OrderSend(Symbol(),orderType,lots,openPrice,5,stopLossPrice,takeProfitPrice,"AFKARIAUS ",MagicBuy,0,clrGreen); if(orderType==OP_SELL) ticket = OrderSend(Symbol(),orderType,lots,openPrice,5,stopLossPrice,takeProfitPrice,"AFKARIAUS ",MagicSell,0,clrGreen); for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicBuy && OrderType()==OP_BUY) BuyTicket=OrderSend(Symbol(),OP_SELLSTOP,lots,OrderOpenPrice()-20*Point,5,OrderOpenPrice()+60*Point,OrderOpenPrice()-20*Point-60*Point,"AFKARIAUS",MagicBuy+1,0,clrBlue); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicSell && OrderType()==OP_SELL) SellTicket=OrderSend(Symbol(),OP_BUYSTOP,lots,OrderOpenPrice()+20*Point,5,OrderOpenPrice()-60*Point,OrderOpenPrice()+20*Point+60*Point,"AFKARIAUS",MagicSell+1,0,clrBlue); } every thing is ok but when test with real money there is Comission,Spreads and Swap.and i dont know what should i do please help me thanks

Cancel quote

Checking account access…