SmartQuant Discussion
http://www.smartquant.com/forums/

OnTrade type of order (Buy or Sell)
http://www.smartquant.com/forums/viewtopic.php?f=42&t=7637
Page 2 of 2

Author:  mapuk [ Thu Jun 23, 2011 2:40 pm ]
Post subject:  Re: OnTrade type of order (Buy or Sell)

Code:
//OnTrade which defines trade Side   
private int positionSide = 0;
private double currentPrice = 0;
public override void OnTrade(Trade trade)
{
   if(currentPrice != 0)
   {
      if(currentPrice == trade.Price)
      {
         if(positionSide == 1)
         {
            //then position side is Buy
   
         }
         else //positionSide == 2
         {
            //then position side is Sell
         }
      }
      else if(trade.Price > currentPrice)
      {
         //then position side is Buy
         positionSide = 1;
         currentPrice = trade.Price;
      }
      else if(trade.Price < currentPrice)
      {
         //then position side is Sell
         positionSide = 2;
         currentPrice = trade.Price;
      }
   }
   else
   {
      currentPrice = trade.Price;
   }
}

Page 2 of 2 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/