Could you explain to me with a brief example how to create it?
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
How to make purchases and sales at the close of the bar and update the stop in ticks
Collapse
X
-
Hello jmarcano,
The same way you have been doing it.
Make a print for:
Code:&& (Position.MarketPosition == MarketPosition.Flat)
Code:&& (VolumeUpDown1.UpVolume[0] > 1300)
Code:&& (CrossAbove(Close, Swing1.SwingHigh, 1))
[CODE]&& (Close[0] > EMA1[0])
Then make a print for:
Code:&& (Operaciones < TradeDay)
Code:&& (Long == true))
You've made one print correctly so far.
Code:Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
If you get stuck, let me know.Chelsea B.NinjaTrader Customer Service
Comment
-
Good afternoon Chelsea, sending the file with the print outputAttached FilesLast edited by jmarcano; 10-12-2020, 04:59 PM.
Comment
-
Thanks ChelseaB, would it be something like this? I'm not very clear on how to declare this condition?
&& (CrossAbove (Close, Swing1.SwingHigh, 1))
This is how I keep the code
// Long
if (IsFirstTickOfBar
&& (Times[0][0].TimeOfDay >= Apertura.TimeOfDay)
&& (Times[0][0].TimeOfDay < Cierre.TimeOfDay)
&& (Position.MarketPosition == MarketPosition.Flat)
&& (VolumeUpDown1.UpVolume[0] > 1300)
&& (CrossAbove(Close, Swing1.SwingHigh, 1))
&& (Close[0] > EMA1[0])
&& (Operaciones < TradeDay)
&& (Long == true))
{
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
// Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
}
Comment
-
Hello jmarcano,
It is important that we see the print (on the first tick of a bar) for every bar and not just when the condition is true.
This is the reason we are using the print above and out side of the condition that triggers the action.
We are choosing to only print on the first tick of a new bar, to cut down on the amount of prints.
This means, you want to print the values outside of the condition set triggering the action.
Do not also add the conditions to the print condition, because then we won't see prints for every bar. We will only see prints when the condition is true, which means we cannot get information when the conditon is not true.
We are only adding prints, we are not changing the condition.
Set the print the condition back to:
if (IsFirstTickOfBar)
Here is an example with the first three prints added:
Code:if (IsFirstTickOfBar) { Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString()); }
Try printing this and let me know if this is not clarifying why we are using prints to see what values are being compared in the condition.
We are trying to see if your condition values are all evaluating as true.
If the condition set evaluates as true the action is triggered.
If the condition set evaluates as false, the action is not triggered.
Chelsea B.NinjaTrader Customer Service
Comment
-
Good morning Chelsea, thanks for your answer, I send you the exit printAttached Files
Comment
-
I send the code with the impressions added.
protected override void OnBarUpdate()
{
// Reset stop
//if ((Position.MarketPosition == MarketPosition.Flat))
//{
//SetStopLoss(CalculationMode.Ticks, Stop);
//}
// Long
if (IsFirstTickOfBar
&& (Times[0][0].TimeOfDay >= Apertura.TimeOfDay)
&& (Times[0][0].TimeOfDay < Cierre.TimeOfDay)
&& (Position.MarketPosition == MarketPosition.Flat)
&& (VolumeUpDown1.UpVolume[0] > 1300)
&& (CrossAbove(Close, Swing1.SwingHigh, 1))
&& (Close[0] > EMA1[0])
&& (Operaciones < TradeDay)
&& (Long == true))
{
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
// Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
}Last edited by jmarcano; 10-13-2020, 09:17 AM.
Comment
-
Hello jmarcano:
Hmm, I don't think I am communicating well that print should not be in the condition we are investigating, or what we are trying to accomplish here.
We need to know the values used in the condition, when the condition is not true.
If you put the print in the condition set, we won't get any prints when the condition is not true.
Would you like to schedule a phone call to discuss why are using prints?
Change:
Code:// Reset stop //if ((Position.MarketPosition == MarketPosition.Flat)) //{ //SetStopLoss(CalculationMode.Ticks, Stop); //} // Long if (IsFirstTickOfBar && (Times[0][0].TimeOfDay >= Apertura.TimeOfDay) && (Times[0][0].TimeOfDay < Cierre.TimeOfDay) && (Position.MarketPosition == MarketPosition.Flat) && (VolumeUpDown1.UpVolume[0] > 1300) && (CrossAbove(Close, Swing1.SwingHigh, 1)) && (Close[0] > EMA1[0]) && (Operaciones < TradeDay) && (Long == true)) { Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString()); Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString()); // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString()); Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString()); Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString()); }
Code:if (IsFirstTickOfBar) { Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString()); Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString()); // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString()); Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString()); Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString()); Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString()); }
Chelsea B.NinjaTrader Customer Service
Comment
-
Sorry, I understood you, I send you updated output
Comment
-
I send the code
protected override void OnBarUpdate()
{
if (IsFirstTickOfBar)
{
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
// Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
}
Comment
-
Hello jmarcano,
Great job removing that.
We also have a few prints that need to be corrected so that they match what you have written into the condition.
-For the condition: "&& (VolumeUpDown1.UpVolume[0] > 1300)"
Change:
Code:Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.[U]UpVolume[/U].ToString() + " > 1300: " + 1300.ToString());
Code:Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume[0]: " + VolumeUpDown1.UpVolume[B][0][/B].ToString() + " > 1300");
-For the condition: "&& (CrossAbove(Close, Swing1.SwingHigh, 1))"
Change:
Code:// Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
https://ninjatrader.com/support/foru...121#post791121
To:
Code:Print("\r\n" + Time[0].ToString() + " Close[1]: " + Close[1].ToString() + " < Swing1.SwingHigh[1]: " + Swing1.SwingHigh[1].ToString() + " && " + " Close[0]: " + Close[0].ToString() + " > Swing1.SwingHigh[0]: " + Swing1.SwingHigh[0].ToString());
-For the condition: "&& (Close[0] > EMA1[0])"
Change:
Code:Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
Code:Print("\r\n" + Time[0].ToString() + " Close[B][0][/B]: " + Close[B][0][/B].ToString() + " > EMA1[B][0][/B]: " + EMA1[B][0][/B].ToString());
With this information we have so far, we can see we are looking for bar between 9:35 and 11:30.
Here is the first print after 9:35.
10/8/2020 9:36:00 AM Times[0][0].TimeOfDay: 09:36:00 => Apertura.TimeOfDay: 09:35:00
10/8/2020 9:36:00 AM Times[0][0].TimeOfDay: 09:36:00 < Cierre.TimeOfDay: 11:30:00
10/8/2020 9:36:00 AM Position.MarketPosition: Flat == MarketPosition.Flat: Flat
10/8/2020 9:36:00 AM VolumeUpDown1.UpVolume: NinjaTrader.NinjaScript.Series`1[System.Double] > 1300: 1300
10/8/2020 9:36:00 AM Close: NinjaTrader.NinjaScript.PriceSeries > EMA1: EMA(NQ 12-20 (2 Minute),20)
10/8/2020 9:36:00 AM Operaciones: 0 < TradeDay: 1
10/8/2020 9:36:00 AM Long: True == true: TrueChelsea B.NinjaTrader Customer Service
Comment
-
-
I send the updated code, I am really very grateful for all the explanations that ChelseaB is giving me
protected override void OnBarUpdate()
{
if (IsFirstTickOfBar)
{
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume[0]: " + VolumeUpDown1.UpVolume[0].ToString() + " > 1300");
Print("\r\n" + Time[0].ToString() + " Close[1]: " + Close[1].ToString() + " < Swing1.SwingHigh[1]: " + Swing1.SwingHigh[1].ToString() + " && " + " Close[0]: " + Close[0].ToString() + " > Swing1.SwingHigh[0]: " + Swing1.SwingHigh[0].ToString());
Print("\r\n" + Time[0].ToString() + " Close[0]: " + Close[0].ToString() + " > EMA1[0]: " + EMA1[0].ToString());
Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
}
Comment
-
Hello jmarcano,
Fantastic, you made it!
But your output file is a little short.
We don't have the output from after 9:35 and before 11:30.
I am only seeing in the file provided:
10/13/2020 12:22:00 PM Times[0][0].TimeOfDay: 12:22:00 => Apertura.TimeOfDay: 09:35:00
10/13/2020 12:22:00 PM Times[0][0].TimeOfDay: 12:22:00 < Cierre.TimeOfDay: 11:30:00
10/13/2020 12:22:00 PM Position.MarketPosition: Flat == MarketPosition.Flat: Flat
10/13/2020 12:22:00 PM VolumeUpDown1.UpVolume[0]: 1 > 1300
10/13/2020 12:22:00 PM Close[1]: 12080.25 < Swing1.SwingHigh[1]: 12181.75 && Close[0]: 12079.75 > Swing1.SwingHigh[0]: 12181.75
10/13/2020 12:22:00 PM Close[0]: 12079.75 > EMA1[0]: 12114.8475789235
10/13/2020 12:22:00 PM Operaciones: 0 < TradeDay: 1
10/13/2020 12:22:00 PM Long: True == true: TrueChelsea B.NinjaTrader Customer Service
Comment
-
If chelseaB, I had to cut it because of the size, it would not let me send them, I send another reduced one to verify
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by love2code2trade, 04-17-2024, 01:45 PM
|
4 responses
31 views
0 likes
|
Last Post Yesterday, 10:31 PM | ||
Started by cls71, Today, 04:45 AM
|
2 responses
10 views
0 likes
|
Last Post
by eDanny
Today, 11:11 AM
|
||
Started by proptrade13, Today, 11:06 AM
|
0 responses
5 views
0 likes
|
Last Post
by proptrade13
Today, 11:06 AM
|
||
Started by kulwinder73, Today, 10:31 AM
|
1 response
10 views
0 likes
|
Last Post Today, 11:01 AM | ||
Started by RookieTrader, Today, 09:37 AM
|
3 responses
15 views
0 likes
|
Last Post Today, 10:32 AM |
Comment