SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Aug 15, 2020 1:50 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Jul 07, 2020 6:08 pm 
Offline

Joined: Wed Jul 01, 2020 7:19 am
Posts: 14
Hi I have little issue on my strategy, using the same code as SMA StopLoss and TakeProfit code, as I posted in previous post,
Using the OnBar, rarely but due to their price fluctuations, the StopLoss and TakeProfit can happen at same Bar, due to the situation as long as using the code from the demo will give us problem in backtest,
Because my strategy enters as long as no position, that is why the Equity curve won't show it correctly.

I know using Bid/Ask data or Realtime trading has no issue but, there are no tick data for 12year, and could download, additionally backtest will be extremely heavy.

So is there a method to avoid this issue?

Thank you very much for your help.

Regards,


Attachments:
Screenshot 2020-07-07 at 11.02.58 PM.png
Screenshot 2020-07-07 at 11.02.58 PM.png [ 34.14 KiB | Viewed 90 times ]
Top
 Profile  
 
PostPosted: Wed Jul 08, 2020 5:44 am 
Offline

Joined: Wed Jul 01, 2020 7:19 am
Posts: 14
Code:
      protected override void OnOrderFilled(Order order)
      {
         if (order == enterOrder)
         {
            if (Position.Side == PositionSide.Long)
            {
               // Calculate prices.
               double takeProfitPrice = [your price];
               double stopLossPrice = [your price];

               // Create orders.
               takeProfitOrder = SellLimitOrder(Instrument, Qty, takeProfitPrice, "TakeProfit "+ Position.EntryDate);
               stopLossOrder = SellStopOrder(Instrument, Qty, stopLossPrice, "StopLoss "+ Position.EntryDate);

               // Send orders.
               Send(stopLossOrder);
               Send(takeProfitOrder);
            }
            else
            {
               // Calculate prices.
               double takeProfitPrice = [your price];
               double stopLossPrice = [your price];

               // Create orders.
               takeProfitOrder = BuyLimitOrder(Instrument, Qty, takeProfitPrice, "TakeProfit "+ Position.EntryDate);
               stopLossOrder = BuyStopOrder(Instrument, Qty, stopLossPrice, "StopLoss "+ Position.EntryDate);

               // Send orders.
               Send(stopLossOrder);
               Send(takeProfitOrder);
            }
         }
         else if (order == stopLossOrder)
         {
            // Cancel take profit order.
            if (!takeProfitOrder.IsDone)
               Cancel(takeProfitOrder);
            else
            {
               if (Position.Side == PositionSide.Long)
               {
                  exceptionOrder = SellOrder(Instrument, Qty, "Exception TakeProfit");
                  Send(exceptionOrder);
               }
               else
               {
                  exceptionOrder = BuyOrder(Instrument, Qty, "Exception TakeProfit");
                  Send(exceptionOrder);
               }   
            }
         }
         else if (order == takeProfitOrder)
         {
            // Cancel stop loss order.
            if (!stopLossOrder.IsDone)
               Cancel(stopLossOrder);
            else
            {
               if (Position.Side == PositionSide.Long)
               {
                  exceptionOrder = SellOrder(Instrument, Qty, "Exception StopLoss");
                  Send(exceptionOrder);
               }
               else
               {
                  exceptionOrder = BuyOrder(Instrument, Qty, "Exception StopLoss");
                  Send(exceptionOrder);
               }
            }
         }
      }


I added exceptionOrder to avoid the issue.

Hopefully this helps somebody!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group