Closeing Problems, Please help - page 3

 

Hello everyone
With everyones help, the symptom has changed.
The statement ....if(OrderSelect(index, SELECT_BY_TICKET) has been chaged to..SELECT_BY_POS. The code is far from being correct. The program sells and then closes immediately after one pip. The result shows that there is no SL or TP. So for a sanity check, I inserted into OrderSend the SL and TP (500) a piece. No change. All executions are within 1 or 2 pips. This is getting interesting. Not sure why, yet! Over a thousand executions occur on one 4 hour bar.
I'll be researching, but any help will be welcomed.

 

Hello Ais
I just posted to find you have posted ahead of me. What you got going?

 

Hello again
I am trying to slightly restyle the program for better logic understanding
I would like the program to please You

 
Ais wrote >>

Hello again
I am trying to slightly restyle the program for better logic understanding
I would like the program to please You

Hello Ais
You are so kind. Thank you. Your time is precious. The restyle I am sure will please.
I have unlocked a part of the problem, since my last post. The program will close, back not as I like.
The key to the closeing problem has been the fact, that I failed to properly initialize the ATR.
I will show you the before and the after for closeing the Sell position.

Then....if (OrderClosePrice() >= OrderOpenPrice() + (ATR*2)
Now.....if (OrderClosePrice() >= OrderOpenPrice() + (40*Point)...This will close the Sell position

This was not how I intended for the program to operate. But for testing purposes I inserted the new code.
It helps to prove that the problem is within the ATR. It must be that I did not properly initialize the ATR.
To further test, I tried to insert the iATR instead of attempting to build a new variable called ATR.
I show you how I tried to code it.

if (OrderClosePrice() >= OrderOpenPrice() + ((iATR(NULL,0,20,1)*2)*Point)

This did not work either.
Thank you again.
I look forward to hear from you.
 

Hello Ais
Thank you for the suggestion. The idea of using 365 (annual) vs my_method, is well taken. Test purposes with shorter timeframe
should be for convenience only.
I do have so much more to learn. I have finally figured how to insert the ATR, yet I can not multiply it. Example follows:

At this time this is what I have......if (OrderClose >= OrderOpenPrice() + (iATR(NULL,0,20,1))) // =Hard Stop
This does work but is not what I want
I'm working towards ...................if (OrderClose >= OrderOpenPrice() + (iATR(NULL,0,20,1) )*2 ),
This does not work. I hope that it demostrates to you and others, as what I have in mind. The iATR is multiplied by 2.
Any suggestions for this??? Once this is solved, I could half the ATR for entry positions as well.

There was another way I attempted but did not work...if(OrderClose - OrderOpenPrice - (iATR(NULL,0,20,1)*2)) <= 0)

Thank you again for your time. I'm sure there are many who are knocking on your door for wisdom.
Cheers
 

Hello Huckleberry,
I left to do only the opening function.
And right now I'm trying to understand the logic of profit fixing.
Stops and takes are missing in your OrderSend(), it is OK, but the command to closing runs only in the case of loss.
And I would like to know your opinion on the understandability of the new program style, https://www.mql5.com/en/forum/124521/page2.
Bye for now,
:)

 

Hello Ais
Thank you for your response.
Let me explain the reason behind no StopLoss or TakeProfit.
By not inserting the SL and TP in the OrderSend, the SL is within a different location, under the expression....

if (OrderClose >= OrderOpenPrice() + (iATR(NULL,0,20,1)))

Although this does work, it is not exactly the proper SL. The example is listed I my last post....

if (OrderClose >= OrderOpenPrice + (iATR(NULL,0,20,1))*2)

The shift in the... iATR, in the above expression may change one bar to the next. By useing the OrderSend with SL and TP, I can not take advantage of the shift change.

Each function works at this time, just that I need to learn how to tweak the functions.
Thank you for your observation and your question.
Cheers

 

It is OK to work without SL and TP.
But we still need condition to close order in case of profit.
Please take a look at the renewed function "iSignalClose",
https://www.mql5.com/en/forum/124521/page2.
Now it is, of course, condition of virtual SL.
But we still need condition of virtual TP.
Waiting for your reply.
:)

 

I inserted for virtual TP the similar with SL condition, but using another factor.
In future will be easy and convinient optimize these parameters.

To optimize declare desirable parameters as "extern".
Example:

////////////////////////////////////////////////////////////////////<         3>
// < 1.1. Data : Input >                                          //<          >
//                                                                //<          >
// < 1.1. Input             7 =       4 i       3 d       - s   > //<          >
// <      1. Strategy       4 =       2 i       2 d       - s  /> //<          >
// <      2. Trading        3 =       2 i       1 d       - s  /> //<          >
// </1.1. Input             7 =       4 i       3 d       - s   > //<          >
//                                                                //<          >
// <      1. Strategy 4 >=========================================//<          >
                    int       iBasePeriod       = 20            ; //<          >
                    int       iBaseBar          = 1             ; //<          >
extern              double    dFactorTP         = 2.0           ; //<          >
extern              double    dFactorSL         = 2.0           ; //<          >
// </     1. Strategy 4 >=========================================//<          >
//                                                                //<          >
// <      2. Trading 3 >==========================================//<          >
                    int       iSlippage         = 1             ; //<          >
                    int       iMagic            = 0             ; //<          >
                    double    dLots             = 0.1           ; //<          >
// </     2. Trading 3 >==========================================//<          >
//                                                                //<          >
//                                                                //<          >
//                                                                //<          >
// </1.1. Data : Input >                                          //<          >
     

After optimization change the original parameter values to the optimized ones and delete "extern" declarations.

Optimization sample for "A System: Championship 2008 Final Edit" also known as "ACB6", https://www.mql5.com/en/forum/112633/page7#276861:
Files:
1e.txt  46 kb
1r.txt  49 kb
Reason: