Can you use the "for loop" in initiation?

 

I was just wondering if it was possible to do so because I have been having trouble with it.

 

Nvm, the problem persists.

 
Looks like I needed to class a variable as a static one to solve the issue.
 

I often use for loops in Init - no problem

Can you give an example of how you are having a problem?

 
GumRai:

I often use for loops in Init - no problem

Can you give an example of how you are having a problem?


Yes of course, although I've fixed the code, fixing the code was a pain because I lost track of what I was doing when I was fixing a minor issue and that it spiraled out, I'm also in the midst of demo trading so as you can imagine  recompiling had some trading effects.

 

I've been trying to construct some initiation code so that my EA is not too greatly effected if I ever have to restart my computer for software upgrades ect, I've coded my EA so that it has some "learning" functionality, however that learning functionality hinges on past performances.

 

Here is some  code for the most recent losses, I have tried to make it so that it selects the most recent loss of the chart symbol and uses that as part of its assessment for future trading.

This is suppose to be the fix

static int LoopT=1;

for(int slp=OrdersHistoryTotal()-1;slp>=0;slp--)
          {
          if(OrderSelect(slp,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
             {
              if(OrderType()==OP_BUY||OrderType()==OP_SELL)
              {
              if(OrderCloseTime()>LoopT){LoopT=OrderCloseTime();}if(OrderCloseTime()==LoopT && OrderProfit()+OrderCommission()+OrderSwap()<0)Stage=2;else Stage=1;
              }
             }
             
          }

 

Stage two is an assessment stage, stage one is regular trading based on past assessment results, I  put the "else stage=1;" in there because I thought that the EA was picking up on losses that were not the most recent as it worked it's way through previously closed trades; the modification seems to have fixed the issue.

I'm not entirely sure where I went wrong because I simply constructed these lines by looking at some of my other lines,  I suppose the "else stage=1;" must have been quite important, I closed quite trades early because of this mess, it's going to effect short term assessments -________- !!