Advertisement
Guest User

Untitled

a guest
Jun 5th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.52 KB | None | 0 0
  1. #region Using declarations
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Xml.Serialization;
  13. using NinjaTrader.Cbi;
  14. using NinjaTrader.Gui;
  15. using NinjaTrader.Gui.Chart;
  16. using NinjaTrader.Gui.SuperDom;
  17. using NinjaTrader.Gui.Tools;
  18. using NinjaTrader.Data;
  19. using NinjaTrader.NinjaScript;
  20. using NinjaTrader.Core.FloatingPoint;
  21. using NinjaTrader.NinjaScript.Indicators;
  22. using NinjaTrader.NinjaScript.DrawingTools;
  23. #endregion
  24.  
  25. //This namespace holds Strategies in this folder and is required. Do not change it.
  26. namespace NinjaTrader.NinjaScript.Strategies
  27. {
  28.     public class MultiStepBreakeven : Strategy
  29.     {
  30.         private int StopLossModeLong;
  31.        
  32.         private int StopLossModeShort;
  33.        
  34.         private int NumberOfTrades;
  35.  
  36.  
  37.         protected override void OnStateChange()
  38.         {
  39.             if (State == State.SetDefaults)
  40.             {
  41.                 Description                                 = @"Enter the description for your new custom Strategy here.";
  42.                 Name                                        = "MultiStepBreakeven";
  43.                 Calculate                                   = Calculate.OnEachTick;
  44.                 EntriesPerDirection                         = 1;
  45.                 EntryHandling                               = EntryHandling.AllEntries;
  46.                 IsExitOnSessionCloseStrategy                = true;
  47.                 ExitOnSessionCloseSeconds                   = 30;
  48.                 IsFillLimitOnTouch                          = false;
  49.                 MaximumBarsLookBack                         = MaximumBarsLookBack.TwoHundredFiftySix;
  50.                 OrderFillResolution                         = OrderFillResolution.Standard;
  51.                 Slippage                                    = 0;
  52.                 StartBehavior                               = StartBehavior.WaitUntilFlat;
  53.                 TimeInForce                                 = TimeInForce.Gtc;
  54.                 TraceOrders                                 = false;
  55.                 RealtimeErrorHandling                       = RealtimeErrorHandling.StopCancelClose;
  56.                 StopTargetHandling                          = StopTargetHandling.PerEntryExecution;
  57.                 BarsRequiredToTrade                         = 20;
  58.                 // Disable this property for performance gains in Strategy Analyzer optimizations
  59.                 // See the Help Guide for additional information
  60.                 IsInstantiatedOnEachOptimizationIteration   = true;
  61.                 StopLossModeLong                    = 0;
  62.                 StopLossModeShort                   = 0;
  63.                 TradeNumberLimit                    = 4;
  64.             }
  65.             else if (State == State.Configure)
  66.             {
  67.             }
  68.         }
  69.  
  70.         protected override void OnBarUpdate()
  71.         {
  72.             if (BarsInProgress != 0)
  73.                 return;
  74.  
  75.             if (CurrentBars[0] < 1)
  76.                 return;
  77.            
  78.             if (CurrentBar < 1)
  79.                 return;
  80.  
  81.  
  82.              
  83.                  //LONG ORDERS
  84.                  // Set 1
  85.                
  86.                 for (int NumberOfTrades = 1; NumberOfTrades <= TradeNumberLimit; NumberOfTrades++)
  87.                 {
  88.                     if (((Time[0].DayOfWeek >= DayOfWeek.Monday) && (Time[0].DayOfWeek <= DayOfWeek.Wednesday))
  89.                          && (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0))
  90.                          && (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
  91.                          && High[0] > High[1])
  92.                     {
  93.                         EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid(), "");
  94.                         StopLossModeLong = 0;              
  95.                     }
  96.                    
  97.                 }
  98.                    
  99.                  // Set 2
  100.                 if ((Position.MarketPosition == MarketPosition.Long)
  101.                      && (StopLossModeLong == 0))
  102.                 {
  103.                     ExitLongStopMarket(Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (-10 * TickSize)) , @"LONG STOP", "");
  104.                 }
  105.      
  106.                  // Set 3
  107.                 if ((Position.MarketPosition == MarketPosition.Long)
  108.                      && (StopLossModeLong == 1))
  109.                 {
  110.                     ExitLongStopMarket(Convert.ToInt32(DefaultQuantity), Position.AveragePrice, @"LONG BE", "");
  111.                 }
  112.      
  113.                  // Set 4
  114.                 if ((Position.MarketPosition == MarketPosition.Long)
  115.                      && (StopLossModeLong == 2))
  116.                 {
  117.                     ExitLongStopMarket(Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (10 * TickSize)) , @"+10 TICKS PROFIT", "");
  118.                 }
  119.      
  120.      
  121.                  // Set 5
  122.                 if ((Position.MarketPosition == MarketPosition.Long)
  123.                      && (StopLossModeLong == 0)
  124.                      && (Close[0] >= (Position.AveragePrice + (10 * TickSize)) ))
  125.                 {
  126.                     StopLossModeLong = 1;
  127.                 }
  128.      
  129.      
  130.                  // Set 6
  131.                 if ((Position.MarketPosition == MarketPosition.Long)
  132.                      && (StopLossModeLong == 1)
  133.                      && (Close[0] >= (Position.AveragePrice + (20 * TickSize)) ))
  134.                 {
  135.                     StopLossModeLong = 2;
  136.                 }
  137.            
  138.         }
  139.     }
  140. }
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement