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
The name "order" does not exist in current context
Collapse
X
-
Hello Kate, I think I figured out what the issue was. I went through my process to add the KeyDown controls step by step and found out lines 696-763
I had misplaced/mispasted a snippet.
PHP Code:else if (State == State.Terminated)
{
if (this.DebugLogLevel > 10) RealLogger.PrintOutput("*** OnStateChange State.Terminated:");
hasRanOnceFirstCycle = false;
hasDrawnButtons = false;
if (attachedInstrumentServerSupported)
{
UnloadAccountEvents();
if (attachedInstrumentIsFuture)
{
if (instrumentsSubscribed)
{
if (this.DebugLogLevel > 10) RealLogger.PrintOutput("*** OnStateChange Unsubscribing to MarketDataUpdate (State.Terminated):");
if (micro1Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(micro1Instrumen t, "MarketDataUpdate", MarketData_Update);
if (micro2Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(micro2Instrumen t, "MarketDataUpdate", MarketData_Update);
if (micro3Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(micro3Instrumen t, "MarketDataUpdate", MarketData_Update);
if (micro4Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(micro4Instrumen t, "MarketDataUpdate", MarketData_Update);
if (emini1Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(emini1Instrumen t, "MarketDataUpdate", MarketData_Update);
if (emini2Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(emini2Instrumen t, "MarketDataUpdate", MarketData_Update);
if (emini3Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(emini3Instrumen t, "MarketDataUpdate", MarketData_Update);
if (emini4Instrument != null) WeakEventManager<Instrument, MarketDataEventArgs>.RemoveHandler(emini4Instrumen t, "MarketDataUpdate", MarketData_Update);
instrumentsSubscribed = false;
}
}
if (ChartControl != null && timer != null)
{
ChartControl.Dispatcher.InvokeAsync(() =>
{
WeakEventManager<System.Windows.Threading.D ispatcherTimer, EventArgs>.RemoveHandler(timer, "Tick", OnTimerTick);
timer = null;
});
}
if (ChartControl != null)
{
if (ChartControl.Dispatcher.CheckAccess())
{
RemoveButtonPanel();
}
else
{
ChartControl.Dispatcher.InvokeAsync((() =>
{
RemoveButtonPanel();
}));
}
}
if (ChartPanel != null)
{
ChartPanel.KeyDown -= ChartPanel_KeyDown;
ChartPanel.KeyUp -= ChartPanel_KeyUp;
}
if (account != null)
{
account.OrderUpdate -= OnOrderUpdate;
account.ExecutionUpdate -= OnExecutionUpdate;
account.PositionUpdate -= OnPositionUpdate;
}
}
}
}
I had
PHP Code:
if (ChartPanel != null)
{
ChartPanel.KeyDown -= ChartPanel_KeyDown;
ChartPanel.KeyUp -= ChartPanel_KeyUp;
}
if (account != null)
{
account.OrderUpdate -= OnOrderUpdate;
account.ExecutionUpdate -= OnExecutionUpdate;
account.PositionUpdate -= OnPositionUpdate;
}
inside the scope of
PHP Code:if (attachedInstrumentServerSupported)
{
}
instead of at State == State.Terminated scope level.
I corrected an now it seems to work.
I'll do some more tests and be back asa. Thanks!Last edited by PaulMohn; 03-14-2022, 08:44 AM.
Comment
-
Kate I still get issue with the order reference.
I've reviewed the Addon sample script and got this far
The order profitTarget declared at
The order profitTarget used in the OnBarUpdate method with the Change() method
The order profitTarget is assigned the Ninjatrader account info in the OnorderUpdate method
Here is the method with the stopOrder
PHP Code:private void CreatePositionStopLoss(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, int quantity, double price)
{
if (orderAction != OrderAction.BuyToCover && orderAction != OrderAction.Sell)
{
RealLogger.PrintOutput("ERROR: Order action of " + orderAction.ToString() + " not supported.");
return;
}
double lastPrice = RealInstrumentService.GetLastPrice(instrument);
bool isValid = RealOrderService.IsValidStopLossPrice(instrument, orderAction, price, lastPrice);
if (orderAction == OrderAction.BuyToCover && !isValid)
{
RealLogger.PrintOutput("ERROR: Stop Loss order price must be greater than last price.");
return;
}
else if (orderAction == OrderAction.Sell && !isValid)
{
RealLogger.PrintOutput("ERROR: Stop Loss order price must be less than last price.");
return;
}
OrderType orderType = OrderType.StopMarket;
lock (account.Orders)
{
string orderName = RealOrderService.BuildStopOrderName();
try
{
Order stopOrder = account.CreateOrder(instrument, orderAction, orderType, orderEntry, TimeInForce.Gtc, quantity, 0, price, "", orderName, Core.Globals.MaxDate, null);
account.Submit(new[] { stopOrder });
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in CreatePositionStopLoss:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
}
I checked if the stopOrder was declared at class level but it's not (it's only present in this method, twice).
The same for the newStopLossPrice order. It's only used locally within those 10 methods
PHP Code:private bool HandleBreakEvenPlus(string signalName)
{
double oldStopLossPrice = 0;
int oldOrderQuantity = 0;
double newStopLossPrice = 0;
private bool HandleStopLossPlus(string signalName, double overrideStopLossPrice = 0)
{
double oldStopLossPrice = 0;
int oldOrderQuantity = 0;
double newStopLossPrice = 0;
private bool HandleSLTPRefresh(string signalName)
{
double oldStopLossPrice = 0;
double oldTakeProfitPrice = 0;
int oldOrderQuantity = 0;
double newStopLossPrice = 0;
private double GetInitialStopLossPrice(MarketPosition marketPosition, double averagePrice, int quantity, double currentStopLossPrice = 0)
{
double newStopLossPrice = currentStopLossPrice;
bool useStopLossTicks = (this.StopLossInitialTicks > 0);
bool useStopLossDollars = (this.StopLossInitialDollars > 0);
private double GetFullStopFromDollars(MarketPosition marketPosition, double averagePrice, int quantity, double fullStopDollars)
{
double newStopLossPrice = 0;
double commissionPerSide = GetCommissionPerSide(attachedInstrument);
bool includeCommissions = (commissionPerSide > 0);
double netStopLossDollars = fullStopDollars;
private double GetStopLossPriceFromJumpTicks(MarketPosition marketPosition, double oldStopLossPrice, int jumpTicks)
{
double newStopLossPrice = 0;
newStopLossPrice = CalculateStopLossPlusPrice(marketPosition, oldStopLossPrice, jumpTicks, attachedInstrumentTickSize, attachedInstrumentTicksPerPoint);
private double CalculateStopLossPrice(MarketPosition marketPosition, double price, int ticks, double tickSize, int ticksPerPoint)
{
double newStopLossPrice = 0;
private double CalculateStopLossPlusPrice(MarketPosition marketPosition, double price, int ticks, double tickSize, int ticksPerPoint)
{
double newStopLossPrice = 0;
private double GetInitialBreakEvenStopLossPrice(MarketPosition marketPosition, double averagePrice)
{
double newStopLossPrice = 0;
private double GetTriggerBreakEvenStopLossPrice(MarketPosition marketPosition, double averagePrice)
{
double newStopLossPrice = 0;
Comment
-
Then I wondered if there were other preexisting uses of .Change() order in the script, and I found 5 methods with .Change( matches
UpdateStopOrder()
PHP Code:private void UpdateStopOrder(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, double price)
{
if (orderAction != OrderAction.BuyToCover && orderAction != OrderAction.SellShort)
{
RealLogger.PrintOutput("ERROR: Order action of " + orderAction.ToString() + " not supported in UpdateStopOrder.");
return;
}
double lastPrice = RealInstrumentService.GetLastPrice(instrument);
if (orderAction == OrderAction.BuyToCover && price <= lastPrice)
{
RealLogger.PrintOutput("ERROR: Stop order price must be greater than last price.");
return;
}
else if (orderAction == OrderAction.SellShort && price >= lastPrice)
{
RealLogger.PrintOutput("ERROR: Stop order price must be less than last price.");
return;
}
bool orderChanged = false;
int orderCount = RealOrderService.OrderCount;
for (int index = 0; index < orderCount; index++)
{
RealOrder order = null;
if (RealOrderService.TryGetByIndex(index, out order))
{
if (RealOrderService.IsValidBuyStopOrder(order, instrument, OrderAction.BuyToCover) || RealOrderService.IsValidSellStopOrder(order, instrument, OrderAction.SellShort))
{
orderChanged = false;
Order foundNTOrder = GetNinjaTraderOrder(order);
if (foundNTOrder.StopPrice != price)
{
foundNTOrder.StopPriceChanged = price;
orderChanged = true;
}
if (orderChanged)
{
try
{
account.Change(new[] { foundNTOrder });
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in UpdateStopOrder:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
}
}
}
}
UpdateLimitOrder() method
PHP Code:private void UpdateLimitOrder(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, double price)
{
if (orderAction != OrderAction.Buy && orderAction != OrderAction.Sell)
{
RealLogger.PrintOutput("ERROR: Order action of " + orderAction.ToString() + " not supported in UpdateLimitOrder.");
return;
}
double lastPrice = RealInstrumentService.GetLastPrice(instrument);
if (orderAction == OrderAction.Buy && price >= lastPrice)
{
RealLogger.PrintOutput("ERROR: Limit order price must be less than last price.");
return;
}
else if (orderAction == OrderAction.Sell && price <= lastPrice)
{
RealLogger.PrintOutput("ERROR: Limit order price must be greater than last price.");
return;
}
bool orderChanged = false;
int orderCount = RealOrderService.OrderCount;
for (int index = 0; index < orderCount; index++)
{
RealOrder order = null;
if (RealOrderService.TryGetByIndex(index, out order))
{
if (RealOrderService.IsValidBuyLimitOrder(order, instrument, OrderAction.Buy) || RealOrderService.IsValidSellLimitOrder(order, instrument, OrderAction.Sell))
{
orderChanged = false;
Order foundNTOrder = GetNinjaTraderOrder(order);
if (foundNTOrder.LimitPrice != price)
{
foundNTOrder.LimitPriceChanged = price;
orderChanged = true;
}
if (orderChanged)
{
try
{
account.Change(new[] { foundNTOrder });
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in UpdateLimitOrder:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
}
}
}
}
UpdatePositionStopLoss() method
PHP Code:private void UpdatePositionStopLoss(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, int quantity, double price)
{
if (orderAction != OrderAction.BuyToCover && orderAction != OrderAction.Sell)
{
RealLogger.PrintOutput("ERROR: Order action of " + orderAction.ToString() + " not supported.");
return;
}
double lastPrice = RealInstrumentService.GetLastPrice(instrument);
bool isValid = RealOrderService.IsValidStopLossPrice(instrument, orderAction, price, lastPrice);
if (orderAction == OrderAction.BuyToCover && !isValid)
{
RealLogger.PrintOutput("ERROR: Stop Loss order price must be greater than last price.");
return;
}
else if (orderAction == OrderAction.Sell && !isValid)
{
RealLogger.PrintOutput("ERROR: Stop Loss order price must be less than last price.");
return;
}
int orderCount = RealOrderService.OrderCount;
for (int index = 0; index < orderCount; index++)
{
RealOrder order = null;
if (RealOrderService.TryGetByIndex(index, out order))
{
if (RealOrderService.IsValidStopLossOrder(order, instrument, orderAction))
{
bool orderChanged = false;
Order foundNTOrder = GetNinjaTraderOrder(order);
if (foundNTOrder.Quantity != quantity && quantity != 0)
{
foundNTOrder.QuantityChanged = quantity;
orderChanged = true;
}
if (foundNTOrder.StopPrice != price)
{
foundNTOrder.StopPriceChanged = price;
orderChanged = true;
}
if (orderChanged)
{
try
{
account.Change(new[] { foundNTOrder });
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in UpdatePositionStopLoss:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
if (quantity != 0) break; //only change one if also setting quantity
}
}
}
}
Comment
-
ConsolidatePositionSLTPOrders() method
PHP Code:private bool ConsolidatePositionSLTPOrders(string signalName, Instrument instrument)
{
bool returnFlag = false;
bool closeAll = false;
int buyOrderCount = 0;
int sellOrderCount = 0;
bool hasSkippedFirst = false;
OrderType stopLossOrderType = OrderType.StopMarket;
OrderType takeProfitOrderType = OrderType.Limit;
List<Order> cancelOrderList = new List<Order>();
int orderCount = RealOrderService.OrderCount;
for (int index = 0; index < orderCount; index++)
{
RealOrder order = null;
bool isFirstStopLossOrder = false;
bool isFirstTakeProfitOrder = false;
Order firstStopLossOrder = null;
Order firstTakeProfitOrder = null;
if (RealOrderService.TryGetByIndex(index, out order))
{
if (RealOrderService.IsValidStopLossOrder(order, instrument, OrderAction.BuyToCover) || RealOrderService.IsValidStopLossOrder(order, instrument, OrderAction.Sell)
|| RealOrderService.IsValidTakeProfitOrder(order, instrument, OrderAction.BuyToCover) || RealOrderService.IsValidTakeProfitOrder(order, instrument, OrderAction.Sell))
{
if (order.OrderType == stopLossOrderType && (order.OrderState == OrderState.Accepted || order.OrderState == OrderState.Working))
{
if (!isFirstStopLossOrder)
{
isFirstStopLossOrder = true;
Order foundNTOrder = GetNinjaTraderOrder(order);
firstStopLossOrder = foundNTOrder;
}
else
{
Order foundNTOrder = GetNinjaTraderOrder(order);
cancelOrderList.Add(foundNTOrder);
}
}
else if (order.OrderType == takeProfitOrderType && order.OrderState == OrderState.Working)
{
if (!isFirstTakeProfitOrder)
{
isFirstTakeProfitOrder = true;
Order foundNTOrder = GetNinjaTraderOrder(order);
firstTakeProfitOrder = foundNTOrder;
}
else
{
Order foundNTOrder = GetNinjaTraderOrder(order);
cancelOrderList.Add(foundNTOrder);
}
}
}
}
int stopLossQuantity = 0;
int takeProfitQuantity = 0;
if (firstStopLossOrder != null)
{
stopLossQuantity = firstStopLossOrder.Quantity;
}
if (firstTakeProfitOrder != null)
{
takeProfitQuantity = firstTakeProfitOrder.Quantity;
}
foreach (Order cancelOrder in cancelOrderList)
{
bool increamentStopLossQuantity = false;
bool increamentTakeProfitQuantity = false;
int initialStopLossQuantity = 0;
int initialTakeProfitQuantity = 0;
int cancelOrderQuantity = 0;
try
{
increamentStopLossQuantity = (cancelOrder.OrderType == stopLossOrderType && firstStopLossOrder != null);
increamentTakeProfitQuantity = (cancelOrder.OrderType == takeProfitOrderType && firstTakeProfitOrder != null);
cancelOrderQuantity = cancelOrder.Quantity;
account.Cancel(new[] { cancelOrder });
if (increamentStopLossQuantity)
{
stopLossQuantity += cancelOrderQuantity;
firstStopLossOrder.QuantityChanged = stopLossQuantity;
account.Change(new[] { firstStopLossOrder });
firstStopLossOrder.Quantity = stopLossQuantity;
}
else if (increamentTakeProfitQuantity)
{
takeProfitQuantity += cancelOrderQuantity;
firstTakeProfitOrder.QuantityChanged = takeProfitQuantity;
account.Change(new[] { firstTakeProfitOrder });
firstTakeProfitOrder.Quantity = takeProfitQuantity;
}
returnFlag = true;
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in ConsolidatePositionSLTPOrders:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
}
return returnFlag;
}
UpdatePositionTakeProfit() method
PHP Code:private void UpdatePositionTakeProfit(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, int quantity, double price)
{
if (orderAction != OrderAction.BuyToCover && orderAction != OrderAction.Sell)
{
RealLogger.PrintOutput("ERROR: Order action of " + orderAction.ToString() + " not supported.");
return;
}
double lastPrice = RealInstrumentService.GetLastPrice(instrument);
bool isValid = RealOrderService.IsValidTakeProfitPrice(instrument , orderAction, price, lastPrice);
if (orderAction == OrderAction.BuyToCover && !isValid)
{
RealLogger.PrintOutput("ERROR: Take Profit order price must be less than last price.");
return;
}
else if (orderAction == OrderAction.Sell && !isValid)
{
RealLogger.PrintOutput("ERROR: Take Profit order price must be greater than last price.");
return;
}
int orderCount = RealOrderService.OrderCount;
for (int index = 0; index < orderCount; index++)
{
RealOrder order = null;
if (RealOrderService.TryGetByIndex(index, out order))
{
if (RealOrderService.IsValidTakeProfitOrder(order, instrument, orderAction))
{
bool orderChanged = false;
Order foundNTOrder = GetNinjaTraderOrder(order);
if (foundNTOrder.Quantity != quantity && quantity != 0)
{
foundNTOrder.QuantityChanged = quantity;
orderChanged = true;
}
if (foundNTOrder.LimitPrice != price)
{
foundNTOrder.LimitPriceChanged = price;
orderChanged = true;
}
if (orderChanged)
{
try
{
account.Change(new[] { foundNTOrder });
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in UpdatePositionTakeProfit:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
if (quantity != 0) break; //only change one if also setting quantity
}
}
}
}
I'll test using the order from the first method and'll be back asa. Thanks!
Comment
-
Hello Kate, I've created a new method (MoveSl()). It's simply a modified version of the preexisting with .Change( method UpdatePositionStopLoss() method (this line is the only modification for now order.StopPriceChanged = Close[0] - (4 * TickSize); ) as
PHP Code:private void MoveSL(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, int quantity, double price)
{
if (orderAction != OrderAction.BuyToCover && orderAction != OrderAction.Sell)
{
RealLogger.PrintOutput("ERROR: Order action of " + orderAction.ToString() + " not supported.");
return;
}
double lastPrice = RealInstrumentService.GetLastPrice(instrument);
bool isValid = RealOrderService.IsValidStopLossPrice(instrument, orderAction, price, lastPrice);
if (orderAction == OrderAction.BuyToCover && !isValid)
{
RealLogger.PrintOutput("ERROR: Stop Loss order price must be greater than last price.");
return;
}
else if (orderAction == OrderAction.Sell && !isValid)
{
RealLogger.PrintOutput("ERROR: Stop Loss order price must be less than last price.");
return;
}
lock (account.Orders)
{
foreach (Order order in account.Orders)
{
if (RealOrderService.IsValidStopLossOrder(order, instrument, orderAction))
{
bool orderChanged = false;
if (order.Quantity != quantity && quantity != 0)
{
order.QuantityChanged = quantity;
orderChanged = true;
}
if (order.StopPrice != price)
{
order.StopPriceChanged = Close[0] - (4 * TickSize);
orderChanged = true;
}
if (orderChanged)
{
try
{
account.Change(new[] { order });
}
catch (Exception ex)
{
RealLogger.PrintOutput("Exception in UpdatePositionStopLoss:" + ex.Message + " " + ex.StackTrace); //log and ignore exception
}
}
if (quantity != 0) break; //only change one if also setting quantity
}
}
}
}
Now I'm trying to call it in the new hotkeys snippet.
I've tried this
PHP Code:TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
MoveSL(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, int quantity, double price)
}
}, null);
e.Handled = true;
Which returned those errors
Then this
PHP Code:TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
MoveSL(signalName, instrument, orderAction, orderEntry, quantity, price)
}
}, null);
e.Handled = true;
and then this
PHP Code:TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
MoveSL("keyPress1", null, Sell, Manual, 0, 0);
}
}, null);
e.Handled = true;
I checked with Visual Studio and got this info for OrderAction and OrderEntry parameters
Why aren't "Sell" and "Manual" valid?
NinjaScript File Error Code Line Column
myTickHunter.cs The name 'Sell' does not exist in the current context CS0103 1311 32
NinjaScript File Error Code Line Column
myTickHunter.cs The name 'Manual' does not exist in the current context CS0103 1311 38
Comment
-
Hello PaulMohn,
Thank you for your replies.
My colleagues and I have had a look over this together as well.
We can't help with modifications to complex scripts, and in order for us to best work with each other, we need to work with small examples. After you are able to accomplish your goals in smaller scripts, you can then use what you have learned to make changes to other scripts.
With the complexity of the script and the information provided, it is a bit overwhelming and we can't give much help.
So we can assist, we should focus on a small example that demonstrates the specific part you are stuck on. Using the example I gave, could you modify it to show your exact issue so it is simplified and can be better reviewed by others?
Thanks in advance; I look forward to assisting you further.Kate W.NinjaTrader Customer Service
Comment
-
Ok thanks for the direction.
For simplification the method I try to call has those 6 parameters
PHP Code:private void MoveSL(string signalName, Instrument instrument, OrderAction orderAction, OrderEntry orderEntry, int quantity, double price)
here's how I tried to call the method
PHP Code:TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
MoveSL("keyPress1", null, Sell, Manual, 0, 0);
}
}, null);
e.Handled = true;
The problem is it's not accepting "Sell" and "Manual" for the OrderAction and OrderEntry parameters and throws those errors:
NinjaScript File Error Code Line Column
myTickHunter.cs The name 'Sell' does not exist in the current context CS0103 1311 32
NinjaScript File Error Code Line Column
myTickHunter.cs The name 'Manual' does not exist in the current context CS0103 1311 38
I'm not sure how to modify the AddOn Framework NinjaScript Basic script to add similar parameters to its .Change() method to make it similar.Last edited by PaulMohn; 03-15-2022, 03:11 PM.
Comment
-
Hello PaulMohn,
Thank you for your reply.
MoveSL() is not a NinjaTrader method, this is a custom method.
When you are writing methods in C#, you need to know what each variable type the parameter is. This is important when you use the method elsewhere. The same rules apply for using any method. You need to know how to use the types it uses, and how to supply the right typed variables to write correct syntax. The compiler is telling you that you have incorrect syntax.
Here is some publicly available information on variable types and writing/using methods
https://docs.microsoft.com/en-us/dot...tructs/methods.
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Please let us know if we may be of further assistance to you.
Kate W.NinjaTrader Customer Service
- Likes 1
Comment
-
Thanks Kate for the doc. Especially the 3rd Types of Variables one
Types of Variables- Local variables
- Instance variables or Non – Static Variables
- Static Variables or Class Variables
- Constant Variables
- Readonly Variables
I previously thought the data type (int, string, double etc.) were the "types" for the variable!
In the same spirit I thought the parameters types for my case were OrderAction and OrderEntry.
After further research i found another snipper in the script
PHP Code:if (DebugLogLevel > 2) RealLogger.PrintOutput(signalName + " opening " + revOrderAction.ToString().ToLower() + " " + tempInstrument.FullName + " Quantity=" + tempQuantity, PrintTo.OutputTab1);
SubmitMar****rder(tempInstrument, revOrderAction, OrderEntry.Automated, tempQuantity);
in light of the types of variables new info (similar to the instance/non-static/below object variable type example in the shared doc), this caught my eye
PHP Code:OrderEntry.Automated
I updated the code to
PHP Code:TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
MoveSL("keyPress1", null, OrderAction.Sell, OrderEntry.Manual, 0, 0);
}
}, null);
e.Handled = true;
And now it's not returning the errors anymore. Thanks!
But I'm not sure of the type of variable those are. It looks like instance/non-static variable because of the object.instancevariable form. In those cases .Sell and .Manual being the instance variables and OrderAction. and OrderEntry. being the objects.
That's what I could guess-infer as OrderAction. and OrderEntry. seem not to be classes (and they can't be local, const or readonly). Is that right? If yes what kind of object are OrderAction. and OrderEntry. ? If that's not correct, would you please explain what those are? How can I know it for sure otherwise? Thanks!Last edited by PaulMohn; 03-15-2022, 04:45 PM.
Comment
-
Hello Kate, I've got it right now.
Following your advice of reducing to the simplest version of the code and building from there, and revisiting the .Change() page and comparing it to the custom method
I came up with this working method and Hotkey command
PHP Code:private void MoveSL()
{
lock (account.Orders)
{
foreach (Order moveSLOrder in account.Orders)
{
moveSLOrder.StopPriceChanged = Close[0] + (4 * TickSize);
account.Change(new[] { moveSLOrder });
}
}
}
PHP Code:TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
// MoveSL("keyPress1", null, OrderAction.Sell, OrderEntry.Manual, 0, 0);
MoveSL();
}
}, null);
e.Handled = true;
i first built the method as bare minimum needed (without the foreach loop) taking example from the .Change() page and added the call to the Hotkey command as
PHP Code:private void MoveSL()
{
moveSLOrder.StopPriceChanged = Close[0] + (4 * TickSize);
account.Change(new[] { moveSLOrder });
}
protected void ChartPanel_KeyDown(object sender, KeyEventArgs e)
{
TriggerCustomEvent(s =>
{
if (Keyboard.IsKeyDown(Key.NumPad1))
{
// MoveSL("keyPress1", null, OrderAction.Sell, OrderEntry.Manual, 0, 0);
MoveSL();
}
}, null);
e.Handled = true;
Then taking example from the Custom method I added the foreach loop.
Many thanks again!
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by fx.practic, 10-15-2013, 12:53 AM
|
5 responses
5,403 views
0 likes
|
Last Post
by Bidder
Today, 12:22 AM
|
||
Started by Shai Samuel, 07-02-2022, 02:46 PM
|
4 responses
94 views
0 likes
|
Last Post
by Bidder
Today, 12:11 AM
|
||
Started by DJ888, Yesterday, 10:57 PM
|
0 responses
6 views
0 likes
|
Last Post
by DJ888
Yesterday, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
158 views
0 likes
|
Last Post Yesterday, 10:23 PM | ||
Started by Belfortbucks, Yesterday, 09:29 PM
|
0 responses
8 views
0 likes
|
Last Post
by Belfortbucks
Yesterday, 09:29 PM
|
Comment