You need to upload the code to try it ...
BUT ... it is clear that one of mistakes is ...
if(STopLoss) double StopLoss = ... * ... +Point;
Instead, you must define StopLoss first like this ...
double StopLoss = 0; if(StopLoss != 0) StopLoss = ......* .....
The same case for TakeProfit ...
Change the code accordingly and see what is the result ...
Also, change line#100 to the following to remove the warning ...
if(OrderSelect(...,...,...)==true)
You need to upload the code to try it ...
BUT ... it is clear that one of mistakes is ...
Instead, you must define StopLoss first like this ...
The same case for TakeProfit ...
Change the code accordingly and see what is the result ...
Also, change line#100 to the following to remove the warning ...
//+------------------------------------------------------------------+ //| EA_v1.mq4 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict // External Variable extern double LotSize = 0.01; extern double StopLoss = 100; extern double TakeProfit = 100; extern int Slippage = 5; extern int MagicNumber = 123; extern int FastMaPeriod = 5; extern int SlowMaPeriod = 8; // Global Variable int BuyTicket; int SellTicket; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { // Moving Average double FastMa = iMA(NULL,0,FastMaPeriod,0,MODE_EMA,PRICE_CLOSE,0); double SlowMa = iMA(NULL,0,SlowMaPeriod,0,MODE_EMA,PRICE_OPEN,0); //Buy Order if (FastMa>SlowMa && BuyTicket==0) { OrderSelect(SellTicket,SELECT_BY_TICKET,MODE_TRADES); // Close Order if (OrderCloseTime()==0 && SellTicket >0) { double CloseLots = OrderLots(); double ClosePrice = Ask;; bool Closed = OrderClose(SellTicket,CloseLots,ClosePrice,Slippage,Red); } // Calculate Stoploss and Take Profit if(StopLoss) double BuyStopLoss = Ask - (StopLoss * Point); if(TakeProfit) double BuyTakeProfit = Ask + (TakeProfit * Point); //Open Buy Order BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize, Ask ,Slippage,BuyStopLoss,BuyTakeProfit, "Order Buy",MagicNumber,0,Green); SellTicket = 0; } //Sell Order if (FastMa<SlowMa && SellTicket==0) { OrderSelect(BuyTicket,SELECT_BY_TICKET); if(OrderCloseTime() == 0 && BuyTicket > 0) { double CloseLots = OrderLots(); double ClosePrice = Bid; bool Closed = OrderClose(BuyTicket,CloseLots,ClosePrice,Slippage,Red); } if(StopLoss > 0) double SellStopLoss = Bid + (StopLoss * Point); if(TakeProfit > 0) double SellTakeProfit = Bid - (TakeProfit * Point); SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage, SellStopLoss, SellTakeProfit,"Sell Order",MagicNumber,0,Red); BuyTicket = 0; } return(0); } // calculate Number of Decimal point in Currency pair and automatically adjusts for 3 and digits.
bool Select=OrderSelect(SellTicket,SELECT_BY_TICKET,MODE_TRADES); { if(Select==1) { if(OrderCloseTime()==0 && SellTicket>0) { bool Closed=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);// Close Order { if(Closed==0) { Print("OrderClose Error!! ",SellTicket); } } } } }
Perfect .
here I want to set condition when moving average crossed UP. enter Buy with 20 point above current price.
and it should not enter if current price is more than 100 Point above Crossed Price.
for example: for Gold
FastMa crossed SlowMA at $1250.
Entre buy at 1250.20 but does not enter if the price was $1251 .
so the range should be between 1250.20 to 1251.
is this correct code?
int PipMinDifference; int PipMaxDifference; double CurrentPrice; if(FastMa > TrendMa + PipMinDifference * Point ) CurrentPrice = iClose(NULL,0,0)+PipMindifference; // Take current close price if(FastMa<=CurrentPrice+PipMaxDifference) // check if current price is below MaximumPipDifference Ex $1251 Order = SIGNAL_BUY;
Perfect .
here I want to set condition when moving average crossed UP. enter Buy with 20 point above current price.
and it should not enter if current price is more than 100 Point above Crossed Price.
for example: for Gold
FastMa crossed SlowMA at $1250.
Entre buy at 1250.20 but does not enter if the price was $1251 .
so the range should be between 1250.20 to 1251.
is this correct code?
CurrentPrice = Close[0] *u can use the price
if(FastMa > TrendMa + PipMinDifference * Point && FastMa > TrendMa + Pip<MaxDifference * Point) Order = SIGNAL_BUY;

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey mates ,
can you please tell me why there are 4 error in my code, I cant fix them .
if(StopLoss) double BuyStopLoss = Ask - (StopLoss * Point);
if(TakeProfit) double BuyTakeProfit = Ask + (TakeProfit * Point);
//Open Buy Order
BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize, Ask ,Slippage,BuyStopLoss,BuyTakeProfit, "Order Buy",MagicNumber,0,Green);
SellTicket = 0;
}