Replies

3rrr168
29 Jan 2021, 01:47

RE:

3rrr168 said:

Hi,

In the following code, I want ExecuteMarketOrder() be executed once only. Most of time, it works well. However, I got ExecuteMarketOrder() be executed twice occasionally. My question is: How do I make ExecuteMarketOrder() be executed once only SURELY?

initially, myflag=0;

protected override void OnTick()
        {
                    if (myflag == 0)
                    {
                        ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits1, myLabel, minusp, aaamt, "a1");
                        myflag++;
                    }
         }

I guess OnTick() is triggered twice occasionally before [myflag++] is finished. If my guess is right, how could I do?

 

I was wrong about this issue. It was a bug of my own. This platform is good at all.

The reason I found about this bug of my own is: when all positions are closing, there is some delay of time for each position, during this period, OnTick() might be triggered several times. The OnTick() is triggered once sometime and is triggered several times occasionally.


@3rrr168

3rrr168
20 Jan 2021, 16:44

RE:

gmkenneyy said:

Why are you triggering simultaneous trades instead of one after the other? - its a recipe for disaster in my opinion.

What i would do is trigger one trade first, then after the close of the next bar, i will check if the market is moving in the direction of my trade before increasing my volume on that trade. This way you have a safety net.

Hi gmkenneyy,

Thank you. I would say that I understand what you said. However, my trading strategy has to trigger the first position by OnTick() event. If I use OnBar() event to trigger the first position, then there will be no problem at all.

By the way, as I know that there are thousands of robots trade based on OnBar() events, thus the very time of OnBar() closed gets larger volume. Some robots use this phenomena the make profit. This is one of the reasons that I do not like to trade based on OnBar() events. Just like the brokers know all your TakeProfits of positions, some brokers will take advantages from you based on those.


@3rrr168

3rrr168
20 Jan 2021, 09:11

RE:

PanagiotisCharalampous said:

Hi 3rrr168,

Are the simultaneous orders executed by the same instance or by different instances?

Best Regards,

Panagiotis 

Join us on Telegram

All the simultaneous orders executed by the same instance. 


@3rrr168

3rrr168
20 Jan 2021, 04:14

RE:

PanagiotisCharalampous said:

Hi 3rrr168,

There are many but you need to provide us with the complete source code and steps to reproduce so that we can understand what the issue is and propose the proper alternative.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you Panagiotis.

There are some information about this issue:

1. In backtesting, this unexpected situation never showed. I guess "the OnTick() events are regular" is the reason.

2. This unexpected situation showed many times during three instances of the same cbot are running. However, it did NOT show all the time. It showed occasionally.

Since my background is Computer Science, I think this issue is related to the multi-thread bug. 

When thread A is driven by OnTick() A, thread A starts running with current variables. If thread A is just beginning, thread B is also driven by OnTick() B, thread B starts running with the same current variables. Then, the unexpected situation shows.

Normally speaking, if CPU is fast enough, the unexpected situation will not show up. If the CPU is slower, it shows up occasionally.

In theory, this is a critical path bug. A critical path allows only one thread all the time.

Hope I am wrong.


@3rrr168

3rrr168
19 Jan 2021, 11:51

RE:

PanagiotisCharalampous said:

Hi 3rrr168,

Try this

protected override void OnTick()
        {
                    if (myflag == 0)
                    {
                        myflag++;
                        ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits1, myLabel, minusp, aaamt, "a1");
                    }
         }

Best Regards,

Panagiotis 

Join us on Telegram

Thank you Panagiotis.

In fact, I did try to place [myflag++] in front of ExecuteMarketOrder(), the results are the same unfortunately. Even if I changed data type of myflag to bool, the results are the same.

Are there any other approaches?

 


@3rrr168

3rrr168
07 Jan 2020, 09:25

Hi Panagiotis,

In the log, I do not see any changes of SL and TSL either.

However, when above error was shown, I watched at the details of that existing position. The SL became null. The TSL became FALSE.

My cBot does place orders with SL=0.5-pips and TSL=TRUE. I also confirmed that the above error is nothing to do with slippages.

I wonder that when error "CONCURRENT_MODIFICATION" happened, the SL and TSL would not be kept. It is a dangerous situation for traders.

Thanks for your response.


@3rrr168