I want to try something a little bit special, but I do not know if it is possible to achieve and how!
for now I just want to do some simple tests and then put this code in more complex codes, so I start with a simple request to find out if it is possible to be realized or not.
for now I want to make sure that I entered a limit order to buy 20 points below the last price (then of course I will indicate in the code of the condition or conditions to active setup).
but not enough...then I want that if the difference between limit orders and last price becomes less than 10 points (in realtime, not in close bar...It is therefore essential), automatically my order is modified and checked back 20 points below the last price (does not have to enter a new one but change the existing order).
There are various strategies that I can use to start, but now I just want to know if I can make this code for my order and how can I create this code, because I do not know if this is possible!
thanks
move my limit order to last price and condition
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
If you can draw the logic out in a flow chart (ie the logic is workable),I want to try something a little bit special, but I do not know if it is possible to achieve and how!
for now I just want to do some simple tests and then put this code in more complex codes, so I start with a simple request to find out if it is possible to be realized or not.
for now I want to make sure that I entered a limit order to buy 20 points below the last price (then of course I will indicate in the code of the condition or conditions to active setup).
but not enough...then I want that if the difference between limit orders and last price becomes less than 10 points (in realtime, not in close bar...It is therefore essential), automatically my order is modified and checked back 20 points below the last price (does not have to enter a new one but change the existing order).
There are various strategies that I can use to start, but now I just want to know if I can make this code for my order and how can I create this code, because I do not know if this is possible!
thanks
then the strategy can be coded.
Re: move my limit order to last price and condition
ok, then I think we can do without any problems.
please let me explain how you can specify the initial code (for now without further conditions), with these steps:
1- I have the last price of the security
2- enter a limit order 20 points below this last price
3- if the last price becomes less than or equal to 10 points from my limit order ....
4- change my limit order and enter 20 points below the last price
this is example of code I want to do, but it is not correct
please let me explain how you can specify the initial code (for now without further conditions), with these steps:
1- I have the last price of the security
2- enter a limit order 20 points below this last price
3- if the last price becomes less than or equal to 10 points from my limit order ....
4- change my limit order and enter 20 points below the last price
this is example of code I want to do, but it is not correct
Code: Select all
inputs:
pointdiff (20),
mindiff (10);
variabile:
var0 (0),
var1 (0),
var2 (0);
var0 = last;
var1 = var0 - pointdiff;
var2 = var0 <= mindiff;
if var0 then buy 1 contract at var1 limit; // place buy limit 1 contract last - 20 point
endif;
if var2 then var1; // this is modify order when the difference last and my buy limit is <= 10 point
endif;
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
For complex concepts, there is only one way to go forward... that is to draw a flowchart first.ok, then I think we can do without any problems.
please let me explain how you can specify the initial code (for now without further conditions), with these steps:
1- I have the last price of the security
2- enter a limit order 20 points below this last price
3- if the last price becomes less than or equal to 10 points from my limit order ....
4- change my limit order and enter 20 points below the last price
this is example of code I want to do, but it is not correct
::
If you dive in head first into coding, you will only run around in circles, and most likely will collapse in frustration.
Here is an example of a flowchart.
- Attachments
-
- flowchart.jpg
- (13.25 KiB) Downloaded 1784 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
ps. Get rid of those generic variable names (ie var0, var1, condition1, etc.).
Declare a meaningful name for each variable, you will save much debug time in the future.
Declare a meaningful name for each variable, you will save much debug time in the future.
Re: move my limit order to last price and condition
ok, now I think about it for well over the weekend and see if I can generate a good code!
thanks for the information how to think
thanks for the information how to think
Re: move my limit order to last price and condition
this is my Flowcharts
- Attachments
-
- diagramma cartesiano.png
- (25.62 KiB) Downloaded 1419 times
Re: move my limit order to last price and condition
excuse my delay, but I've had a very busy and I could not continue in this study!
I tried to write a bit of code, starting with the first step...indicating that for now only have to enter a limit order, this is code:
I indicated "NEXT BAR..." because in this bar is not approved!
if I swich ORDER = TRUE, But nothing happens, no order is sent to the market
quickly remember what I do in this first step....
if I swich ORDER in TRUE, I want enter a limit order 20 points\tick under the last price.
I tried to write a bit of code, starting with the first step...indicating that for now only have to enter a limit order, this is code:
Code: Select all
inputs:
pointdiff (20),
order (false);
variables:
lastprice (0),
differencedown (0);
lastprice = last;
differencedown = lastprice - pointdiff;
if order=true then buy 1 contract next bar at differencedown limit;
I indicated "NEXT BAR..." because in this bar is not approved!
if I swich ORDER = TRUE, But nothing happens, no order is sent to the market
quickly remember what I do in this first step....
if I swich ORDER in TRUE, I want enter a limit order 20 points\tick under the last price.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
Are you referring to live trading? or backtest?::
if I swich ORDER = TRUE, But nothing happens, no order is sent to the market
::
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
Look up the definition and usage example ofexcuse my delay, but I've had a very busy and I could not continue in this study!
I tried to write a bit of code, starting with the first step...indicating that for now only have to enter a limit order, this is code:
Code: Select all
inputs:
pointdiff (20),
order (false);
variables:
lastprice (0),
differencedown (0);
lastprice = last;
differencedown = lastprice - pointdiff;
if order=true then buy 1 contract next bar at differencedown limit;
I indicated "NEXT BAR..." because in this bar is not approved!
if I swich ORDER = TRUE, But nothing happens, no order is sent to the market
quickly remember what I do in this first step....
if I swich ORDER in TRUE, I want enter a limit order 20 points\tick under the last price.
LAST
Re: move my limit order to last price and condition
sorry, in dictionary of multicharts I see only " Last = for will return the price of the last trade " ( I want to use it )....in basic manual, in various forum or web search I find no other references to the use of last price!
where can I find information on its use, please?
or should I use another function, for my purpose?
where can I find information on its use, please?
or should I use another function, for my purpose?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
Maybe that's a hint?sorry, ... I find no references to the use of last price!
Did you miss this line in the description?
I am not saying that is the cause of your problem; whatever is happening to you requires more information and analysis. But at least you should try to avoid using quote fields for calculations. For the indicator calculations, you should use the keyword CLOSE instead.
Notes
Quote Fields cannot be referenced historically.
Re: move my limit order to last price and condition
sorry, I had not realized before!
I modified Lasto to Close, but I can not send to the order...
I try with a base code, to proceed step by step.
in this "base code" I try simply to enter a limit order 20 point down close price, but nothing happens and I do not receive either error alerts.
is the wrong part of the definition... " next bar at....." ?
I modified Lasto to Close, but I can not send to the order...
I try with a base code, to proceed step by step.
Code: Select all
inputs:
pointdiff (20),
order (false);
variables:
barclose (0),
differencedown (0);
barclose = close;
differencedown = barclose - pointdiff;
if order=true then buy 1 contract next bar at differencedown limit;
is the wrong part of the definition... " next bar at....." ?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: move my limit order to last price and condition
Probably there is something wrong with your logic.
Did the price ever trade there?
See post #2
viewtopic.php?f=16&t=10811
Did the price ever trade there?
See post #2
viewtopic.php?f=16&t=10811
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: move my limit order to last price and condition
Not sure if you're aware of this or if it's already mentioned in this thread, but your code will recalculate `differencedown` on each bar (or each tick if intra-bar order generation is turned on).in this "base code" I try simply to enter a limit order 20 point down close price, but nothing happens and I do not receive either error alerts.Code: Select all
inputs:
pointdiff (20),
order (false);
variables:
barclose (0),
differencedown (0);
barclose = close;
differencedown = barclose - pointdiff;
if order=true then buy 1 contract next bar at differencedown limit;
This means that the following can happen (for example):
Bar 1. Close 2000. `differencedown` limit order = 1980
Bar 2. Close 1998. `differencedown` limit order = 1978
Bar 3. Close 2005. `differencedown` limit order = 1985
Bar 4. Close 2011. `differencedown` limit order = 1991
Bar 5. Close 2020. `differencedown` limit order = 2000
In other words, unless the next bar moves more than 20 points away from the close, your limit order won't be executed but "moves along" the price the whole time.
You can change this behaviour by changing the code, like this:
Code: Select all
Inputs:
PointDiff(20),
Order(false);
Variables:
barClose(0),
IntraBarPersist differenceDown(0);
// Only calculate the limit price once,
// normally this is done when the entry signal
// is triggered. But here an input is used, so
// let's use LastBarOnChart_s as a substitute:
once (LastBarOnChart_s) begin
differenceDown = Close - PointDiff;
end;
if (order = true) then
buy 1 contract next bar at differenceDown limit;
Re: move my limit order to last price and condition
thanks, maybe I'm wrong some setting, even with the code that you have shown me the orders are not placed....the steps that I have:
1- insert code in "signals" and compile, of course
2- I open the chart of the instrument and active trading mode (I try manual orders, it's ok)
3- I insert the signal in the graph
4- in property, auto trading, my broker is correct, other options I leave everything unchanged
5- I turn on "TRUE" the signal indicator
I make these steps but nothing happens!
I tried other signal indicators (only signals, without trading live mode!) and go well, what went wrong in this?
1- insert code in "signals" and compile, of course
2- I open the chart of the instrument and active trading mode (I try manual orders, it's ok)
3- I insert the signal in the graph
4- in property, auto trading, my broker is correct, other options I leave everything unchanged
5- I turn on "TRUE" the signal indicator
I make these steps but nothing happens!
I tried other signal indicators (only signals, without trading live mode!) and go well, what went wrong in this?
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: move my limit order to last price and condition
The code works for me, and I don't had to enable or disable certain special settings. Have you also tried the signal on Playback Data? Then you can check whether the issue is with the signal or the order submitting in live trading.
Btw, I really do hope that with 'active trading mode' you meant a demo account because code examples given on the forum don't substitute a real strategy. For example, this strategy keeps buying as long as the `Order` input is set to true.
Btw, I really do hope that with 'active trading mode' you meant a demo account because code examples given on the forum don't substitute a real strategy. For example, this strategy keeps buying as long as the `Order` input is set to true.
Re: move my limit order to last price and condition
yes, now I have also tried Playback Date, but not send orders. I also tried with two different brokers that use, if I put the orders manually all is well, if I enable this TS does not send orders!
this code does not use it to trade, it is only a small part to solve this code limit orders, my wish is then to create a more elaborate TS...then I create the conditions that if true must send this limit order, if conditions change, however, I have to cancel or change the order limit to another price.
I want to get this final result
I try to see why not work orders or seeking a similar code to try if it works well.
this code does not use it to trade, it is only a small part to solve this code limit orders, my wish is then to create a more elaborate TS...then I create the conditions that if true must send this limit order, if conditions change, however, I have to cancel or change the order limit to another price.
I want to get this final result
I try to see why not work orders or seeking a similar code to try if it works well.