Cancel Order when Level "tested"

Questions about MultiCharts and user contributed studies.
Largo
Posts: 6
Joined: 07 Sep 2018
Has thanked: 1 time
Been thanked: 1 time

Cancel Order when Level "tested"

Postby Largo » 17 Sep 2018

Hello,
I am not a coder but I had my share of trying out and research, so I hope it is ok to bother you guys now.
I want to code a Signal that is managing my trade. The easy stuff is working fine (timing, stopp, profit...), but some core things are just not working. My current problem:
- I want my Limitorder to be cancelled once the level got "tested".

For example:
Limitorder (buy) is at 100, current price is at 150. The price is now dropping to 110, then moving back to 150. My entrylevel is now "tested" and I dont want to trade that level anymore.

I was trying to fix that with variables (see below), but that is not working. Do you have any ideas or is it just a dumb idea that I want to realize this in MC? Thanks a lot in advance!

The "tested level" code:

Code: Select all

Inputs:
L1( 0 ),
MyStopTicks( 30 ),
MyProfitTicks( 30 ),
MyBreakEvenTicks( 10 ),
MyTestedTicks( 5 );

var:
varL1(0),
varL1Test3(0),
varL1Test10(0),
varCountL1(0),
checkit1(0);

varL1 = L1;
varL1Test3 = varL1 +MyTestedTicks;
varL1Test10 = varL1 +MyProfitTicks;

if CurrentAsk <= varL1Test3 then checkit1 = checkit1 +1;
if CurrentAsk >= varL1Test10 and checkit1 > 0 then varCountL1 = varCountL1 +1;

if varL1 > 0 and varCountL1 = 0 then buy("L1") MyContracts contracts next bar varL1 limit;
And the full Signal, just for reference:

Code: Select all

[IntrabarOrderGeneration = true];

// IMPORTANT PRE-SETTINGS
Inputs:
FromMonth( 0 ),
FromDay( 0 ),
FromTime( 0 ),
RedNewsStart( 0 ),
MyContracts( 1 );
// LEVELS
Inputs:
L1( 0 ),
L2( 0 ),
S1( 0 ),
S2( 0 );
// TRADE MANAGEMENT
Inputs:
MyStopTicks( 30 ),
MyProfitTicks( 30 ),
MyBreakEvenTicks( 10 ),
MyTestedTicks( 5 );
// OTHER SETTINGS
Inputs:
RedNewsDoNotOpenBefore( 30 ),
RedNewsDoNotOpenAfter( 30 ),
RedNewsCloseAllBefore( 5 );
// VARIABLES
var:
varL1(0),
varL1Test3(0),
varL1Test10(0),
varCountL1(0),
checkit1(0);
// DEFINITIONS
varL1 = L1;
varL1Test3 = varL1 +MyTestedTicks;
varL1Test10 = varL1 +MyProfitTicks;
// CONDITIONING
if Month(date) = FromMonth and dayofmonth(date) >= FromDay and Time >= FromTime then begin
// CODING L1
if CurrentAsk <= varL1Test3 then checkit1 = checkit1 +1;
if CurrentAsk >= varL1Test10 and checkit1 > 0 then varCountL1 = varCountL1 +1;

if varL1 > 0 and varCountL1 = 0 then buy("L1") MyContracts contracts next bar varL1 limit;
setstoploss_pt(MyStopTicks);
setprofittarget_pt(MyProfitTicks);
end;

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Cancel Order when Level "tested"

Postby TJ » 18 Sep 2018

Step One in designing a strategy:- Draw diagrams (with notes) to illustrate your vision.

Not just one diagram,
but multiple diagrams to show how the strategy should behave under different circumstances.


Scenario you should consider:
1. What is the critical point?
2. How to establish the critical point?
3. What if the critical point is touched?
4. What if the critical point is exceeded?
5. What if the critical point is exceeded then retreated?
6. What are the other considerations?
7. . . .


For example:
Attachments
ua.JPG
(49.25 KiB) Downloaded 267 times

Largo
Posts: 6
Joined: 07 Sep 2018
Has thanked: 1 time
Been thanked: 1 time

Re: Cancel Order when Level "tested"

Postby Largo » 20 Sep 2018

Step One in designing a strategy:- Draw diagrams (with notes) to illustrate your vision.
...but I had my share of trying out and research, so I hope it is ok to bother you guys now.
My intention why I wrote this in the beginning was to highlight that I did all that. I think my mistake was that I did not show here what exactly I try because I thought this (simple) problem was solved very quickly. Sorry for that.

My idea was to have variables change their value (from 0 to 1 or higher) at two events:
- If the price is close to the Limitprice (checkit1)
- The price has been close to the Limitprice beforen AND THEN the price is far away from my Limitprice (varCountL1)

Now I want my signal to check the variable "varCountL1" and if it is >0 to simply NOT execute my order. I attached my drawing which I did in the beginning so that you can have a look. I am thankful for every approach and if you were looking for a signal that can do this- of course I am willing to share it once it is finished.

Image


Return to “MultiCharts”