Need help modifying Take profit and Stop Loss to show on the chart

JayB
38
JayB  

Hello. May you assist me with this Expert Advisor i am coding. I don't have programming background but i am still learning.

1. i would like to modify my TakeProfit and StopLoss. 

i have put a Take profit of 150 before, now i modified it to 500 but still shows 150 once it opens a trade

I am suspecting that i may have missed something but i do not know where exactly on the code below. May you help

 //Buy 10 microlot
   if (signal =="buy" && PositionsTotal()<
1 )
   trade.Buy(0.10,NULL,Ask,(Ask-1000*_Point),(Ask+500 *_Point),NULL);


2. The EA is only executing one trade. Until that trade reaches TakeProfit and close, its not executing another trade when conditions are met.

So it has to open another buy trade when conditions are met despite having another open trade that has a TakeProfit and Stoploss. 

Here is the full code

   #include  <Trade\Trade.mqh>

   //Create an instance of CTrade
   CTrade trade;
   
void OnTick()
  {
   //We calculate the Ask price
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   
   //We calculate the Bid price
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   
   //We create an array for the prices
   MqlRates PriceInfo[];
   
   //Sort the price array from the current candle downwards
   ArraySetAsSeries(PriceInfo,true);
   
   //We fill the array with price data
   int PriceData =CopyRates(_Symbol,_Period,0,3,PriceInfo);
   
   //Create a string for the signal
   string signal="";
   
   //Create 2 Arrays for Ichimoku and SMA
   double IchimokuArray[],ShiftedAverageArray[];
   
   //we define Ichimoku
   int IchimokuDefinition = iIchimoku(_Symbol,_Period,9,9,52);
   
   //we define Shifted Average
   int ShiftedAverageDefinition = iMA(_Symbol,_Period,1,2,MODE_SMA,PRICE_CLOSE);
   
   //Sort the price array from the current candle downwards
   ArraySetAsSeries(IchimokuArray,true);
   
   //Sort the price array from the current candle downwards
   ArraySetAsSeries(ShiftedAverageArray,true);
   
   //we fill the array with price data
   //Defined EA, one line, current candle for 10 candles, store in array
   CopyBuffer(IchimokuDefinition,0,0,10,IchimokuArray);
   
   //we fill the array with price data
   CopyBuffer(ShiftedAverageDefinition,0,0,10,ShiftedAverageArray);
   
   //Buy signal
   //if the price is above the Tenkansen
   if (ShiftedAverageArray[0]<IchimokuArray[0])
   
   //and was above the Ichimoku before
   if (ShiftedAverageArray[1]>IchimokuArray[1])
   {  signal="buy"; }
     
   //Buy 10 microlot
   if (signal =="buy" && PositionsTotal()<2)
   trade.Buy(0.10,NULL,Ask,(Ask-1000*_Point),(Ask+500 *_Point),NULL);
   
   //chat output
   Comment("The signal is now: ",signal);

Note: As a learner i was putting command and instructions so that i dont forget.