Login Page - Create Account

Support Board


Date/Time: Mon, 23 Dec 2024 00:35:51 +0000



Post From: Trailing Stop Attached Order

[2015-08-28 05:12:46]
CustomIndicators - Posts: 126
I'm trying to get a bot to set a trailing stop connected to an order, but I'm not having the result I wanted. My bot had gotten into a trade, but didn't seem to set the trailing stop like I thought it would. Am I doing something wrong? How can I get an attached trailing stop to work? I couldn't find anything that would give me a better result. Here is a sample of my code that gets in, but not out.


s_SCPositionData PositionData;
int Result = sc.GetTradePosition(PositionData);
int PositionStatus = PositionData.PositionQuantity;

int chartNumber = 3;

if (PositionStatus <= 0 && sc.GetStudyPersistentIntFromChart(chartNumber - 1, 1, 1) == 1 && sc.GetStudyPersistentIntFromChart(chartNumber, 1, 1)) {
    // Go Long

    int Amount = (PositionStatus * -1) + 1;

    s_SCNewOrder GoLong;
    GoLong.OrderQuantity = Amount;
    GoLong.OrderType = SCT_MARKET;
    
    int Result = sc.BuyEntry(GoLong);

    if (Result > 0) {
      
      s_SCNewOrder TrailingStop;
      TrailingStop.OrderQuantity = PositionStatus;
      TrailingStop.OrderType = SCT_ORDERTYPE_TRAILING_STOP;
      TrailingStop.Price1 = sc.BaseData[SC_LAST][sc.Index] - TrailingStopTicks.GetInt()*sc.TickSize;
      
      sc.SellExit(TrailingStop);
    }

  }