I have created a strategy that creates values and once a stock reaches those values a limit order is to be placed just below the market price. I have confirmed that the values and variables are being calculated correctly by forming an indicator out of the strategy and plotting the values. The strategy is also not generating any syntax errors and compiles properly. However, when I run the strategy no buy orders are ever sent out. Is there an issue with using values as limit order amounts?
This is the code to generate the order:
value12 = (var11+0.06) ;
value11 = (var11+0.02) ;
condition1 = close = value12 ;
if condition1 then buy ("New Entry") 1000 shares next bar at value11 limit ;
My understanding is that condition1 is that if the last price is equal to value12 then a limit order will be sent out at the amount of value11. I have also tried using a market order to see if that would allow orders to be sent out but that too did not work.
Is there something wrong with how I am writing this?
Thanks in advance for your help.
Orders/Conditions with values [SOLVED]
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Orders/Conditions with values
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713
see also post #4 in the link
The First Step in Debugging Your Code.
viewtopic.php?f=16&t=11713
see also post #4 in the link
The First Step in Debugging Your Code.
Re: Orders/Conditions with values
Sorry about that, here is the code:
I am using MultiCharts64 for TWS Version 8.9 Release (Build 10289).
Code: Select all
value12 = (var11+0.06) ;
value11 = (var11+0.02) ;
condition1 = close = value12 ;
if condition1 then buy ("New Entry") 1000 shares next bar at value11 limit ;
Re: Orders/Conditions with values
I see two things that jump out. First, you should change the order of var11 and var12, since var12 is a function of the value of var11.
And rather than write condition1 = close = value12; to define condition1, just delete that line and for your order generating line of code write
if close = value12 then begin
buy 1000 shares next bar at value 11 limit;
end;
Right now you are saying if condition1, then buy 1000 shares next bar at value11 limit; versus saying if condition1 = true, then buy 1000 shares next bar at value11 limit;
So the way it is written you are never truly saying when MC should buy because you just say if condition1 then buy. You don't specify what condition1 is supposed to =
And rather than write condition1 = close = value12; to define condition1, just delete that line and for your order generating line of code write
if close = value12 then begin
buy 1000 shares next bar at value 11 limit;
end;
Right now you are saying if condition1, then buy 1000 shares next bar at value11 limit; versus saying if condition1 = true, then buy 1000 shares next bar at value11 limit;
So the way it is written you are never truly saying when MC should buy because you just say if condition1 then buy. You don't specify what condition1 is supposed to =
Re: Orders/Conditions with values
Thanks so much for your help!
I have made the changes but no buy arrows/ticks show up on the chart indicating a buy would have been made on the backtest, even though the values would have been hit on several occasions.
Any other ideas?
I have made the changes but no buy arrows/ticks show up on the chart indicating a buy would have been made on the backtest, even though the values would have been hit on several occasions.
Any other ideas?
Re: Orders/Conditions with values
Do you see trade detail in your performance report? If so, then make sure your setting are such to actually show the trade detail on the chart.Thanks so much for your help!
I have made the changes but no buy arrows/ticks show up on the chart indicating a buy would have been made on the backtest, even though the values would have been hit on several occasions.
Any other ideas?
Re: Orders/Conditions with values
When I look at the performance report not one trade is being executed either.
Re: Orders/Conditions with values
Thank you so much for your continued help. This is the latest version of the buy
Code: Select all
value11 = (var11+0.06) ;
value12 = (var11+0.02) ;
if close = value11 then begin
buy ("New Entry") 1000 shares next bar at value12 limit ;
Re: Orders/Conditions with values [SOLVED]
That snippet of code looks correct to me so there is likely an issue elsewhere in the signal. Can you post more or if not too long, all of your signal so we can see where the problem(s) are.
If you'd rather not post all of your signal, feel free to PM me and I am happy to work off line via email if that is better for you.
If you'd rather not post all of your signal, feel free to PM me and I am happy to work off line via email if that is better for you.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Orders/Conditions with values
I have made the changes but no buy arrows/ticks show up on the chart indicating a buy would have been made on the backtest, even though the values would have been hit on several occasions.
There's a small issue with your code: the `value12` variable holds the limit order price. But this `value12` variable is also recalculated each time the script executes!Thank you so much for your continued help. This is the latest version of the buy
Code: Select all
value11 = (var11+0.06) ;
value12 = (var11+0.02) ;
if close = value11 then begin
buy ("New Entry") 1000 shares next bar at value12 limit ;
So what happens is that your limit order is not a fixed price, but changes with each calculation -- it's value is always 0.02 more than `var11`. Though we don't know what `var11` is, this issue does fit the description you're giving here.
So instead, try something like this:
Code: Select all
Variables:
var11(0),
enterLong(false);
value11 = (var11+0.06) ;
enterLong = Close > Close[1];
// Only calculate the limit price when
// there's an entry condition.
// That way we don't update our limit order
// with each new tick/bar.
if (enterLong = true) then begin
value12 = (var11+0.02);
end;
if close = value11 then
buy ("New Entry") 1000 shares next bar at value12 limit ;
Re: Orders/Conditions with values
Hi Josh,
Thanks so much for your help but that too is not triggering an order.
In the PM Tony sent to me he provided this advice:
Thanks so much for your help but that too is not triggering an order.
In the PM Tony sent to me he provided this advice:
And it worked last night for triggering orders but this morning does not. I am completely confused how the code can work one day and not work the next day?Hi:
Two things stand out. One is when you have IOG=True, I believe variables need to be defined as
intrabarpersist var0(0);
Versus right now you just have
var0(0);
This allows their prior values to be stored. Don't quote me on that, but I believe you need to do that.
Here is something else though. You are telling MC to buy if close = value1, but I believe you also need to specify MarketPosition=0, meaning if flat, to buy. So I would change as follows:
If close = value1
AND MarketPosition = 0
Then begin
Buy ("new entry")....
Would you try those two changes and see what happens. If no luck, then try a third thing. At the very bottom of your script put in the below line
print(value1,close);
and then run your script and see on the output tab of PLE what values it prints for value1 and close.
Re: Orders/Conditions with values
The issue has been solved.
For those curious, I had to use the round function to round var0 to the nearest penny as it was being calculated to a precise number to fractions of a penny, a price that a stock would never equal; therefore, the buy orders weren't being triggered properly.
Thanks very much to Tony and Josh for their help!!
For those curious, I had to use the round function to round var0 to the nearest penny as it was being calculated to a precise number to fractions of a penny, a price that a stock would never equal; therefore, the buy orders weren't being triggered properly.
Thanks very much to Tony and Josh for their help!!