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 rhyminkevin, Today, 04:58 PM
      1 response
      33 views
      0 likes
      Last Post Anfedport  
      Started by iceman2018, Today, 05:07 PM
      0 responses
      4 views
      0 likes
      Last Post iceman2018  
      Started by lightsun47, Today, 03:51 PM
      0 responses
      7 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      14 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      49 views
      0 likes
      Last Post futtrader  
      Working...
      X