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!
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
NinjaTrader
Scalling in positions when losing
Collapse
X
-
Hello YakusaTrader,
Thank you for your response.
You would need to manually track the first execution through OnExecutionUpdate() as there is not a direct access to the initial entry for the position.
Please visit the following link for details on OnExecutionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm
Please let me know if you have any questions.
Leave a comment:
-
Position.AveragePrice is the average entry price of all opened positions, is there a way to identify the initial entry position?
Leave a comment:
-
I appreciate your help.
I put something together -- it's working thank you!
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class ScallingUp : Strategy
{
private double Counter;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "ScallingUp";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 100;
EntryHandling = EntryHandling.UniqueEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
OrderFillResolution = OrderFillResolution.High;
OrderFillResolutionType = BarsPeriodType.Minute;
OrderFillResolutionValue = 1;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlatSynchronizeAccount;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
Distance = 20;
QTY = 1;
Profit = 10;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 20)
return;
// Set 1
if (Close[0] > Close[1] && (Position.MarketPosition == MarketPosition.Flat))
{
EnterLong(QTY, "");
Counter = 1;
}
// Set 2
if ((Position.MarketPosition != MarketPosition.Flat)
&& (Close[0] <= (Position.AveragePrice - (Distance * TickSize * Counter))))
{
EnterLong(QTY, "");
Counter += 1;
}
if ((Position.MarketPosition != MarketPosition.Flat)
&& (Close[0] >= (Position.AveragePrice + (Profit * TickSize))))
{
ExitLong();
}
if (Position.MarketPosition == MarketPosition.Flat)
{
Counter = 0;
}
Print("Counter is : " + Counter);
Print(Time[0]);
Print("Quantity is : " + Position.Quantity);
}
#region Properties
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(Name="Distance", Order=1, GroupName="Parameters")]
public int Distance
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="QTY", Order=2, GroupName="Parameters")]
public int QTY
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Profit", Order=3, GroupName="Parameters")]
public int Profit
{ get; set; }
#endregion
}
}
Leave a comment:
-
Hello YakusaTrader,
Thanks for your post.
There are some internal rules to opening positions in the opposite direction when you are already in position, however these rules would not effect entering another position in the same direction.
The strategy would just have to have Entries Per Direction and EntryHandling to be set to allow multiple entries in the same direction. The logic would then need to be defined to control your entries and subsequent entries.
I've included documentation resourced on these items as well the Managed Approach's Internal Rules for further reading.
Entry Handling - https://ninjatrader.com/support/help...ryhandling.htm
Entries Per Direction - https://ninjatrader.com/support/help...rdirection.htm
Managed Approach Internal Rules - https://ninjatrader.com/support/help...antedPositions
Please let us know if we can be of further assistance.Last edited by NinjaTrader_Jim; 09-13-2018, 12:33 PM.
Leave a comment:
-
Scalling in positions when losing
Hi,
Is there a way to open new positions every 20 ticks from initial position (same direction) when it is still open and losing?
Example:
If my initial position is still open and 20 ticks losing, then open additional position 1, if my initial position is still open and 40 ticks losing, then open additional position 2, etc...
Thank you very much in advance.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pechtri, 06-22-2023, 02:31 AM
|
9 responses
122 views
0 likes
|
Last Post Today, 02:31 PM | ||
Started by frankthearm, 04-18-2024, 09:08 AM
|
16 responses
66 views
0 likes
|
Last Post Today, 02:17 PM | ||
Started by habeebft, Today, 01:18 PM
|
1 response
5 views
0 likes
|
Last Post Today, 02:03 PM | ||
Started by benmarkal, Today, 12:52 PM
|
2 responses
13 views
0 likes
|
Last Post
by benmarkal
Today, 02:00 PM
|
||
Started by f.saeidi, Today, 01:38 PM
|
1 response
7 views
0 likes
|
Last Post Today, 01:45 PM |
Leave a comment: