I am trying to invert my Trading Algo, any clues?

 

Hi, I have an RSI-Trader EA I made that simply makes trades at certain RSI levels at different changeable RSI settings. Some pairs it works fine on some pairs not so much. I want to know why when I try to invert the trading mechanism, so that  in the two different if, else brackets instead of buy the EA sells and instead of sell the EA buys, using a 1:1 Ratio, that when I rerun the algo I would get inverted results on the pairs that did not perform. When I switched the place of the buy and sell functions, and re-ran the algo the results where different but not completely inverted. Any clues?


Here is the code:

#property copyright "Copyright 2021, NENFB LLC"
#property link      "https://www.NENFBLLC.com"
#property version   "2.00"

#include <Trade/Trade.mqh>
#include <Expert\Trailing\TrailingFixedPips.mqh>
#include <Expert\Expert.mqh>

//-------------------------------------------------------------------------

// Initialized Variables

input double Lots = 1;           
input double TpPoints =  500000.00;
input double SlPoints = 100000.00;

double upper_band = 62.50;
double mid_upper_band = 56.25;
double mid_lower_band = 43.75;
double lower_band = 37.50;
int mid_rsi = 50; 

input int ma_period = 49;

int handle;
int totalBars;

CTrade trade;

//==================================================================================================
int OnInit()
  {
  
   totalBars = iBars(_Symbol,PERIOD_CURRENT);  
   handle = iRSI(_Symbol,PERIOD_CURRENT,ma_period,PRICE_CLOSE);
 
   
   Print("OnInit...");
   return(INIT_SUCCEEDED);
  }

//-------------------------------------------------------------------------

void OnDeinit(const int reason)
  {

   Print("OnDeinit...");
   
  }

void OnTick(){

int bars = iBars(_Symbol,PERIOD_CURRENT);
   
   if(totalBars != bars){
      totalBars = bars;
   
      double rsi[];
      
      CopyBuffer(handle,0,1,3,rsi);
      
      // if(rsi[2] > upper_band && rsi[1] > upper_band && rsi[0] < upper_band){
      if(rsi[1] > upper_band && rsi[0] < upper_band){
         Print("Sell Signal");
         
         double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
         bid = NormalizeDouble(bid,_Digits);
         
         double sl = bid + SlPoints *_Point;
         sl = NormalizeDouble(sl,_Digits);
         
         double tp = bid - TpPoints *_Point;
         tp = NormalizeDouble(tp,_Digits);
         
         trade.Sell(Lots,_Symbol,bid,sl,tp);
      
      // }else if(rsi[2] < lower_band && rsi[1] < lower_band && rsi[0] > lower_band){
      }else if(rsi[1] < lower_band && rsi[0] > lower_band){
         Print("Buy Signal");
         
         double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
         ask = NormalizeDouble(ask,_Digits);
         
         double sl = ask - SlPoints *_Point;
         sl = NormalizeDouble(sl,_Digits);
         
         double tp = ask + TpPoints *_Point;
         tp = NormalizeDouble(tp,_Digits);
         
         trade.Buy(Lots,_Symbol,ask,sl,tp);
      }     
   } 
  }
 
Muso LLC:

Hi, I have an RSI-Trader EA I made that simply makes trades at certain RSI levels at different changeable RSI settings. Some pairs it works fine on some pairs not so much. I want to know why when I try to invert the trading mechanism, so that  in the two different if, else brackets instead of buy the EA sells and instead of sell the EA buys, using a 1:1 Ratio, that when I rerun the algo I would get inverted results on the pairs that did not perform. When I switched the place of the buy and sell functions, and re-ran the algo the results where different but not completely inverted. Any clues?


Here is the code:

Maybe because you switch only the functions? What about SL and TP ?? 😁
Reason: