Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 DJ888, Today, 10:57 PM
      0 responses
      1 view
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      158 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Today, 09:29 PM
      0 responses
      7 views
      0 likes
      Last Post Belfortbucks  
      Started by zstheorist, Today, 07:52 PM
      0 responses
      7 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      151 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Working...
      X