Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't a brother just pass a variable?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can't a brother just pass a variable?

    Ok, this could get super complicated quick so I'll try to keep it simple and let you ask question if you don't follow me.
    Task: Store "AllTrades" - Quantity. Then pass the data to my "private double _sizeDoubler" so I can increase the my lot size if the last trade was a loss.
    I have wrote many different configurations. I'll leave what I feel should definitely be working below:

    The following code is written below "OnExecutionUpdate".


    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    private void MartingaleManagment(Order order)
    {
    double _sizeDoubler = 0;
    var lossInPips = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPips;
    var lossInPoints = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPoints;
    var sizeLastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Quantity;

    if (lossInPips <= 0 || lossInPoints < 0)
    {
    _sizeDoubler = (int) lastTradeQty;

    if (MyMarketType == MarketType.Forex)
    {
    _posSize = _(int) _sizeDoubler * 8;
    }

    else if (MyMarketType == MarketType.Other)

    _posSize = (int) _sizeDoubler * 8;

    }
    else
    {
    _posSize = InitialLotSize;
    }
    }


    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    I have tries a lot of variations of this. Getting AllTrades info under "OnBarUpdate". Declairing "_sizeDoubler" as a private and public Double at the top with the other varables. What am I doing wrong here? The Logic for finding if the last trade was a loss works. I just can't get the trade size data from the last trade. Or last losing trade...

    Here is another attempt:

    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    (In OnBarUpdate)

    if (SystemPerformance.AllTrades.Count > 0)
    {
    // Check to make sure there is at least one trade in the collection
    Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];

    lastTradeQty = lastTrade.Quantity;
    Print("The last trade's quantity " + (lastTradeQty));
    }


    (In OnExecutionUpdate)
    private void MartingaleManagment(Order order)
    {
    var lossInPips = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPips;
    var lossInPoints = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPoints;

    if (lossInPips <= 0 || lossInPoints < 0)

    if (MyMarketType == MarketType.Forex)
    {
    _posSize = (int) lastTradeQty* 8;
    }

    else if (MyMarketType == MarketType.Other)

    _posSize = (int) lastTradeQty * 8;

    }
    else
    {
    _posSize = InitialLotSize;
    }
    }

    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Any thoughts?


    #2
    Well never mind, I figured it out. It seems I need to get tired pushing for too long, freak out and write to you guys. Then grab a coffee and find that the answer comes to me! Thanks anyway!

    Comment


      #3
      Originally posted by White Fork View Post
      Well never mind, I figured it out. It seems I need to get tired pushing for too long, freak out and write to you guys. Then grab a coffee and find that the answer comes to me! Thanks anyway!
      I think it taking too long for you!

      cps test

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      52 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      142 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      160 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      96 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X