The use of Bool Variables/State.SetDefaults values
ChaseProfitTarget = true;
PrintDetails = false;
TrailStopLoss = true;
UseProfitTarget = true;
UseStopLoss = true;
as Properties Region Variables
#region Properties
[NinjaScriptProperty]
[Display(Name = "Chase profit target", Order = 2, GroupName = "NinjaScriptStrategyParameters")]
public bool ChaseProfitTarget
{ get; set; }
[NinjaScriptProperty]
[Display(Name = "Print details", Order = 7, GroupName = "NinjaScriptStrategyParameters")]
public bool PrintDetails
{ get; set; }
[NinjaScriptProperty]
[Display(Name = "Trail stop loss", Order = 5, GroupName = "NinjaScriptStrategyParameters")]
public bool TrailStopLoss
{ get; set; }
[NinjaScriptProperty]
[Display(Name = "Use profit target", Order = 1, GroupName = "NinjaScriptStrategyParameters")]
public bool UseProfitTarget
{ get; set; }
[NinjaScriptProperty]
[Display(Name = "Use stop loss", Order = 4, GroupName = "NinjaScriptStrategyParameters")]
public bool UseStopLoss
{ get; set; }
#endregion
to create Checkboxes in the indicator Properties Windows (from the Chart window, Ctrl+I - attached image boolsascheckboxes).
Then the use of a a List to store submitted and changed orders
private List<Order> changeOrdersArray, submitOrdersArray;
Then changing an order using it's limitPrice/stopPrice parameter value only (new way to change order)
profitTargetOrder.LimitPriceChanged = currentPtPrice;
stopLossOrder.StopPriceChanged = currentSlPrice;
Then the way the chase is made
currentPtPrice = orderUpdateArgs.AverageFillPrice + ProfitTargetDistance * TickSize;
profitTargetOrder = submissionAccount.CreateOrder(orderUpdateArgs.Orde r.Instrument, OrderAction.Sell, OrderType.Limit, OrderEntry.Automated,
TimeInForce.Day, orderUpdateArgs.Quantity, currentPtPrice, 0, oco, "Profit Target", Core.Globals.MaxDate, null);
if (ChaseProfitTarget && profitTargetOrder != null &&
(profitTargetOrder.OrderState == OrderState.Accepted || profitTargetOrder.OrderState == OrderState.Working) &&
Close[0] < currentPtPrice - ProfitTargetDistance * TickSize)
{
currentPtPrice = Close[0] + ProfitTargetDistance * TickSize;
profitTargetOrder.LimitPriceChanged = currentPtPrice;
changeOrdersArray.Add(profitTargetOrder);
}
ensuring the Target is only moved to the downside, by manipulating the currentPtPrice variable.
For example:
The Target is set to EntryPrice + 10 Ticks initially.
Then Price must move below EntryPrice to lower currentPrice as much.
Then Price must move below Price at the time/level of previous currentPrice change for currentPrice to change again.
How did you arrive at this algorithm? What principles did you use? it seems obvious but it's not for the uninitiated. it dizzies the forehead.
ProfitTargetDistance
currentPrice
profitTargetOrder
I see you keep ProfitTargetDistance constant, and use the Close[0] down ticks in reference to itself to move down exclusively the profitTargetOrder order. That I understand.
I'm thinking it is some sort of cyclical algorithm/reasoning you use. How do you see the cyclical part of if before you code it? I'm struggling a lot with that part, so much so that I have to commit to memory the form of it to keep a hint/prompt of it as arbitrary figure to recall when needing that sort of "cyclical" algorithm, but I cannot "see it work" first and then code it myself.
How do you yourself "see it work" first and then code it?
I mean what training specifically made you able to derive that cyclical multiple layers processes operations condensed into one? Is there a specific Computer Science domain that trains that multiple / condensed operations "reasoning"? You condensed things that aren't seeming to go "well" together. And it's not just about algebra, nor just about rote experience/reading many scripts.
I know the close is the key, i.e. that's the variable that will be used to move the Target (that's the basic idea that will need to be used anyway you turn the problem).
I know currentPrice is the Target's order limitPrice variable so that will also need to be used to move the Target.
What I don't know/I can't foresee is
How do you/what do you do to see the cycle before coding it? What do you "train" to "think/see" the cycle in code. Is there a computer science domain that can train that cyclical reasoning? How do you personally approach the problem? Do you draw coordinates on some graph? Do you use some sort of flow chart? Do you use the number/numerical computation to derive the right formula? Do you use an app? Anything else?
I managed to reproduce the steps for 2 down moves in a formula in cyclicalalgo attached picture but it's not enough to get the cyclical concept out of it.
Thanks!
Comment