Something is wrong with the short positions of the ATR scalping strategy

Course Name: Day Trading Strategies for Beginners, Section No: 8, Unit No: 10, Unit type: Notebook



Hi!

I looked through the data and noticed that most of the short positions are wrong.

They are being opened at the same time as long positions. I didn't do any editing to the code from Quantra.



Also they most of them are starting at the open at 9:30. I tried to find the mistake in the code, but couldn't find it!



Where is the mistake?

Hi Sami,



Could you please elaborate the short positions are wrong how? 

Did you mean visually on the graph? If that is the case, that is misleading because of the small scale.

You could see the difference in the data frame that long and short positions don't open at the same time.



Also, they don't always start at 9:30 as it can be seen by running : msft[msft['positions']==-1]



Could you please clarify if the above explanation dispels your doubt?

I'm referring to the "trades" DataFrame. I looked through it and noticed that most of the short positions are being opened at the same time as the long positions, and also most of them at 9:30



Hi Sami,

We are working on a solution to this problem and shall get back to you shortly. 

Thanks!


Hey Sami

Thanks for highlighting this. On further review, we found that the entry time update was missing while initiating short positions. This caused the short position entry time to match with the long position entry time. If you add the highlighted code in red below, the correct entry time for the short position should be reflected. Regarding the positions at market open. The chances of making four candle high/low are higher at market open due to gap up or gap down opening compared to other times of the day. Therefore, more trades are opened at the market open.



    # Short Position
    if (current_position == 0) and (msft.loc[time, 'positions'] == -1):
        current_position = -1
        entry_time = time
        entry_price = msft.loc[time, 'close']


I hope this helps.
 

Cool! Thanks!

This is interesting!