Swapping Buy to Sell did not work

Konut  

Hello folks,

started learning MQL for more than a week now.

made EA which simply opens order based on PARABOLIC SAR indicator.

on sell indicator it sells and on buy indicator it buys. and I lost 100% loss in a year. while backtesting.

I swapped the signal from sell to buy and buy to sell, thinking this loss should now be a profit as stoploss and takeprofit are at same level.

but it did not work I still was down by 50%

Am I missing something, as I am very new to forex.

void OnTick()
  {
 //Ask price
double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

// Bid price
double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

//creat an empty string for the signal

string signal="" ;

MqlRates PriceArray[];

//Sort array from the current candle
ArraySetAsSeries(PriceArray,true);

//Array with price
int Data = CopyRates(_Symbol,_Period,0,3,PriceArray);


//creat a SAR array
double mySARArray[];

//define SAR EA
int SARdefinition = iSAR (_Symbol,_Period,0.02,0.2);

//sort the array form the current candle downward

ArraySetAsSeries(mySARArray,true);

CopyBuffer(SARdefinition,0,0,3,mySARArray);
 
 
 //Calculate the value for the last candle
 double LastSARValue =NormalizeDouble(mySARArray[1],5);
 
 //buy signal
 
 if (LastSARValue<PriceArray[1].low)
 
 {
 signal ="Buy"; 
 }
 
 if (LastSARValue>PriceArray[1].low)
 

 {
 signal ="Sell";
 }
 
 
 if (signal==
"Sell" && PositionsTotal()<1)
 trade.Sell(0.10,NULL,Bid,(Bid+100*_Point),(Bid-100*_Point),NULL);
 
if (signal==
"Buy" && PositionsTotal()<1)
 trade.Buy(0.10,NULL,Ask,(Ask-100*_Point),(Ask+100*_Point),NULL); 
 
 Comment("\n","\n","THe Signal",signal);
  }

Vladimir Karputov  
Mistake number 1: MQL5 style implies that the indicator handle must be created ONCE and must be done in OnInit!
Konut  

Hi Vladimir,

Thanks for your response, I am not sure why it should only be in OnInit and not in OnTick.

I have no programming background, Can you guide me some online resource to learn MQL5 from beginner to advance.

google suggest nothing but this website.

This website contains details but very difficult for me to understand the terminology.

Vladimir Karputov  
Konut #:

Hi Vladimir,

Thanks for your response, I am not sure why it should only be in OnInit and not in OnTick.

I have no programming background, Can you guide me some online resource to learn MQL5 from beginner to advance.

google suggest nothing but this website.

This website contains details but very difficult for me to understand the terminology.

Example: how to get the value of the iSAR indicator in an advisor.
How to start with MQL5
How to start with MQL5
  • 2020.08.26
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
Reason: