Little help with my code

Questions about MultiCharts and user contributed studies.
aczk
Posts: 67
Joined: 08 Feb 2012
Has thanked: 8 times
Been thanked: 1 time

Little help with my code

Hi All

Can't get this to work. Want to short the days open to close, condition is that the day before price criss crosses the high of the day before that (highd(1)) a few times (4-6). Can't get it to short on the open, it just short after enough crosses. Appreciate any help!!

Code: Select all

`Inputs:    Price(H+L/2),profitstop(4500), highCrosseson1(4);vars:      highdCrosseson1(0), newday(false);// Yesterday, price criss crosses around yesterday's high several times.// Let's count those crossesif marketposition = 0 and price crosses over highd(1) then begin;   highdCrosseson1 = highdCrosseson1 + 1;end;// Trade only the next dayif date[1] < date then begin   newday=true;end;// Yesterday High crosses enough and its a new dayif highdCrosseson1 >= highCrosseson1 and newday then begin;   {price cross below lowd(1)} sellshort this bar at close;end;   // Var Resets   if marketposition = -1 then begin;   highdCrosseson1 = 0;end;if date[1] < date then highdCrosseson1 = 0;// Stopssetexitonclose;`

TJ
Posts: 6482
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 956 times
Been thanked: 1867 times

Re: Little help with my code

aczk wrote:Hi All

Can't get this to work. Want to short the days open to close, condition is that the day before price criss crosses the high of the day before that (highd(1)) a few times (4-6). Can't get it to short on the open, it just short after enough crosses. Appreciate any help!!
...

can you draw a diagram to illustrate your logic?
or maybe a flowchart to describe your vision?

aczk
Posts: 67
Joined: 08 Feb 2012
Has thanked: 8 times
Been thanked: 1 time

Re: Little help with my code

Hi thx for taking a look.

On the picture:

Day 1 price criss crosses around the high of the prior day (plotted in green). I want to count these crosses and if enough go short at the open of the next day.Simple!

thx
Attachments
Picture1.png (128.99 KiB) Viewed 154 times

TJ
Posts: 6482
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 956 times
Been thanked: 1867 times

Re: Little help with my code

aczk wrote:Hi thx for taking a look.

On the picture:

Day 1 price criss crosses around the high of the prior day (plotted in green). I want to count these crosses and if enough go short at the open of the next day.Simple!

thx

Concepts always sound simple.
Execution is another story.

My suggestions:

1. don't jump into writing a strategy. Start with an indicator, plot a dot on the chart when your logic is met. Then you can visually inspect the chart and see if a trade is feasible.

2. Write out your logic step by step. What you have written is a concept. You will need to expand on the concept and drill down into detail instructions.
eg.
a. What does it mean by "count these crosses"? Can you go through your thinking process and write out how you are counting? When the counting is done, plot a green dot if the count is good, and plot a red dot if the count is not sufficient?

b. What is "and if enough"? Do you have a counter? how many variables do you need to keep track of? How do you count them? What is the criteria of a count?

You have a good concept... you will need a bit more work to lay out the logic.
These users thanked the author TJ for the post:
JoshM

Posts: 616
Joined: 09 Apr 2010
Has thanked: 379 times
Been thanked: 225 times
Contact:

Re: Little help with my code

Try using the "Count Criteria SM" indicator in MC .(I think it is built-in). That should allow you to plot those crossover conditions and adjust the number of crosses(occurrences) is adjustable.
The "Criteria" is an input, so just substitute the price crossing the line on the screen for the default Criteria. TJ is right (as usual), using an indicator to test the logic is usually a much simpler way to see if a potential strategy has promise.

aczk
Posts: 67
Joined: 08 Feb 2012
Has thanked: 8 times
Been thanked: 1 time

Re: Little help with my code

hi guys thx for the tips.
I employ a similar routine to spot if a potential system can work.

My question was more about how to structure something in easy language:

I want to count something that happened yesterday, like the price crosses an important line (e.g.:highd(1)) or moving average a few times.

Then I wait for the next day and sellshort if condition was met yesterday.

That is how far I got, code below. However if I add another condition like for example to only sellshort if the price is above yesterdays high, the whole thing falls apart. Any help on the code? Can't figure out the resets of the count vars I think!

Code: Select all

`Inputs:    Price(H+L/2),profitstop(4500), highCrosseson1(2); vars:      highdCrosseson1(0), countstop(false), newday(true);   if date[1] < date then begin   newday = true;end;// Count the following:// Yesterday, price criss crosses around yesterday's high several times.if countstop = false then begin;   if price crosses over highd(1) then begin;      highdCrosseson1 = highdCrosseson1 + 1;   end;end;// Yesterday High crosses enough and its a new dayif highdCrosseson1 >= highCrosseson1 then begin;   countstop = true;end;if countstop = true and date[1] < date then begin;   sellshort next bar at market;end;   // Var Resets   if marketposition = -1 or date[1] < date then begin;   highdCrosseson1 = 0;   countstop = false;   end;if date[1] < date then highdCrosseson1 = 0;// Stopssetprofittarget(profitstop);setexitonclose;`