Learning to pivot extra positions into code, Help

 

Hello to all

The existing code does work. I will post the code in the next message within this thread. Yes, this code does work, not that it is profitable, but it is a great learning tool. The system at this time trades one position at a time (enters a position, then closes that particular position). What I can not get my head around is to enter a position e.g. BUY, then as the market increases, the system will add on an additional positions of equal value. The system needs to have this function as an 'extern' so as to determine the amount of positions (tickets), the code will allow. For instance 4 or 5 additional postions.

I am not sure, but the function which closes the positions will liquidate all postions when the above function is included in the code, but the function must be modified to a trailing stop instead.

// <      1.1.1. Strategy 4 >=====================================//<          >
                     extern double    MaximumRisk    = 0.1      ; //<          >
                     extern double    Lots           = 0.1      ; //<          >
                     extern int       iBaseLag       = 7        ; //<          >
                     extern int       iBaseBar       = 1        ; //<          >
                   //  extern double    dFactorTP      = 1.0      ; //<          >
                     extern double    dFactorSL      = 1.0      ; //<          >
//Need to include extern that allows additional positions, such as :
                     extern double    dPivot         = 4        ; //<          >


// </     1.1.1. Strategy 4 >=====================================//<          >
//                                                                //<          >
// <      1.1.2. Trading 4 >======================================//<          >
                  //  int       iTradeBarOnce     = 1             ; //<          >
                    int       iSlippage         = 1             ; //<          >
                    int       iMagic            = 1             ; //<          >
                    double    dLots             = 1             ; //<          >
// </     1.1.2. Trading 4 >======================================//<          >

Additional positions are entered every half dATR. dATR = iATR ( 0, 0, iBaseLag, iBaseBar) . Therefore, if the ATR = 104, an additional position of equal value is added on to the trade at 52 pips. e.g. Entered at 1. 45331. an additional BUY position is added on to the trade at 1.45851. This does pose a problem, because if the market is in a good upward trend, the dFactorTP will take profit before the dPivot reaches its maximum position allowed. dPivot is climbing the value of 2*ATR. The dFactorSL would do better if it were trailing instead of being fixed. If the extern dFactorSL was modified to a trailing stop, the dFactorTP could be eliminated. Then code could follow the trend along with the additional positions and not be liquidated prior to markets maximum potential, which the dFactorTP allows.

I have attached the code for further study. Although this code exists, I will not take complete credit for its development. Everyone here has helped, but a big thank you goes to Ais.

Any further help is appreciated.

Huckleberry

Files:
 

Hello Huckleberry

This code needs to be restructured to meet your new demands, because the current structure was developed for work with only one position.
If you don't mind I'd joined to this process too.
But I need more precise information, may be simple answers "yes" "no" on my technical questions.
It is because my English not quite perfect yet.
As I understand, now this program must be able to maintain more than one open order simultaneously.
If you say "yes", I'd start to prepare the new structure of the program, more flexible and, I hope, more simple.
And, most important, I suggest you to do it in MQL5.
May be it will be not so fast as usually, because I work with another projects too, in C++ now, but it will be much useful for all us.

High regards

 

Hello Airat

It is good tom hear from you. Hope that all is well. Your English is understood.

Yes the program would be better if it could be developed in MQL5. I remember you mentioning that you would be learning the MQL5 a few months ago.

OK. As to your questions 'yes and no.' Yes the program must carry more than one open position at a time. Possiblly more than 5. To liquidate, the positions will be closed all at the same time basically. The old code provided a stop loss at 2* ATR fixed. Where as, the new code needs a trailing stop at 2* ATR at all times.

There will be the entry position and more positions of equal value will be added at half an ATR. Such as the example above. Entry at 1.45331 with an ATR value at 104. So the next value to use for entry would be 1.45851. (104 / 2 = 52. 1.4331 + 520 = 1.45851.)

For Optimization purposes, could the amount of positions be calculated in the 'extern double'. Such as mentioned above, dPivot? dPivot will determine the range for optimization such as 1 to 5 and dFactorSL worked very well. Could this be implicated into the new program.

Thank you, and I will be back.

Best Regards

Benjamin