Multiple loops failing

 

Hello everybody

I am new to programming EA and I have been following some videos and so far, I was able to make a strategy run smoothly. I was testing the following:

- EMA 1H 34 periods / EMA 1H 8 periods

-Alligator M5 (EMA, no shift)

Also, I addeded a loop for trailing stop.

This was working fine, but I realized my strategy was lacking recognizing the last swing as signal to open a trade. And for this, I was trying to add a zigzag indicator. Again, I was watching a video and followed the idea, but now, my strategy won't open trades. I have been reading my EA, but I just can't see where I went wrong... can you help me, please? Thank you!!

This is my OnTick()

void OnTick(){

               int indexCurrent = -1, indexLast = -1;

               for(int a = 0; a < 10000; a++){
               double indiRed[];
               CopyBuffer(handleZigZag,1,a,1,indiRed);
               double indiGreen[];
               CopyBuffer(handleZigZag,2,a,1,indiGreen);
               
               if(indiGreen[0] > 0 || indiRed[0] > 0){
                  if(indexCurrent < 0){
                     indexCurrent = a;
                  }else{
                     indexLast = a;
               
                     datetime time = iTime(_Symbol,PERIOD_M5,a);
                     if(time > lastSignal){
                                      
                        if(indiGreen[0] > 0){
                        }else if(indiRed[0] > 0){
                 
                        }
                     }
                     lastSignal = time;
        
                     }}};

         for(int i = 0; i < PositionsTotal(); i++){
               ulong posTicket = PositionGetTicket(i);

               if(PositionGetSymbol(POSITION_SYMBOL) != _Symbol)
               continue;
               if(PositionGetInteger(POSITION_MAGIC) != Magic)
               continue;
               
               double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
               double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
               
               double posPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
               double posSL = PositionGetDouble(POSITION_SL);
               double posTp = PositionGetDouble(POSITION_TP);

               if(PositionGetInteger(POSITION_TYPE)== POSITION_TYPE_BUY){
                  if(bid > posPriceOpen + TslTriggerPoints * _Point){
                     double sl = bid - TslPoints * _Point;
                     sl = NormalizeDouble(sl,_Digits);
               
                     if(sl > posSL){
                        trade.PositionModify(posTicket,sl,posTp);
                                    }
                   }
               }
               else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){
                        if(ask < posPriceOpen - TslTriggerPoints * _Point){
                           double sl = ask + TslPoints * _Point;
                           sl = NormalizeDouble(sl,_Digits);
               
                           if(sl < posSL || posSL == 0){
                                 trade.PositionModify(posTicket,sl,posTp);
                              }
                        }
                     }
               
               
               int bars = iBars(NULL, AlligatorTimeFrame);
               if(barsTotal != bars){
                  barsTotal = bars;
                  double jaws[];
                  double teeth[];
                  double lips[];
                  double EMAFast[];
                  double EMASlow[];
                  CopyBuffer(handleAlligator,GATORJAW_LINE,1,1,jaws);
                  CopyBuffer(handleAlligator,GATORTEETH_LINE,1,1,teeth);
                  CopyBuffer(handleAlligator,GATORLIPS_LINE,1,1,lips);
                  CopyBuffer(handleEMAFast,0,1,1,EMAFast);
                  CopyBuffer(handleEMASlow,0,1,1,EMASlow);
                  
                  int low6bars = iLowest(NULL,AlligatorTimeFrame,MODE_LOW,5,0);
                  double low6barsprice = iLow(NULL,AlligatorTimeFrame,low6bars);
                  low6barsprice = NormalizeDouble(low6barsprice,_Digits);
                  double entry = SymbolInfoDouble(NULL,SYMBOL_ASK);
                  entry = NormalizeDouble(entry,_Digits);
                  double sl = low6barsprice - 50*_Point;
                  sl = NormalizeDouble(sl,_Digits);
                  double tpcount= (entry - sl)/_Point;
                  double tp = entry + tpcount*2*_Point;
                  tp = NormalizeDouble(tp,_Digits);
               
               
                  if(EMAFast[0] > EMASlow[0] && entry > EMAFast[0] && lips[0] > teeth[0] && teeth[0] > jaws[0]){
                     trade.Buy(Lots, NULL,entry,sl,tp,"TEMAStrategy");}
                  else if(EMAFast[0] < EMASlow[0] && entry < EMAFast[0] && jaws[0] > teeth[0] && teeth[0] > lips[0]){
                  
                           int high6bars = iHighest(NULL,AlligatorTimeFrame,MODE_HIGH,5,0);
                           double high6barsprice = iHigh(NULL,AlligatorTimeFrame,high6bars);
                           high6barsprice = NormalizeDouble(high6barsprice,_Digits);
                           double entry = SymbolInfoDouble(NULL,SYMBOL_BID);
                           entry = NormalizeDouble(entry,_Digits);
                           double sl = high6barsprice + 50*_Point;
                           sl = NormalizeDouble(sl,_Digits);
                           double tpcount= (sl - entry)/_Point;
                           double tp = entry - tpcount*2*_Point;
                           tp = NormalizeDouble(tp,_Digits);
                           
                           
                           trade.Sell(Lots,NULL,entry,sl,tp,"TEMAStrategy");
                          }
                          }
                          }
                         }
 
Fernanda:
CopyBuffer(handleZigZag,1,a,1,indiRed);                double indiGreen[];                CopyBuffer(handleZigZag,2,a,1,indiGreen);
CopyBuffer(handleZigZag,1,a,1,indiRed);
CopyBuffer(handleZigZag,2,a,1,indiGreen);

why you copy ZigZag buffers inside a loop? this makes it slow. copy all of them one time. 


Also where did you used zigzag output for your trading decisions?! you just find swing high/low (not sure if even find them correctly) then... nothing!


is this from Chat GPT.. or any other AI?!