+1 888 340 6572 



Post new topic Reply to topic 
Little help with my code   [ ]
Author Message
#1 posted 09 Mar 2012 

Status: Offline
Posts: 62
Thanks Received: 1 time
Thanks Given: 7 times
Joined: 08 Feb 2012
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:
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 crosses
if marketposition = 0 and price crosses over highd(1) then begin;
   highdCrosseson1 = highdCrosseson1 + 1;
end;

// Trade only the next day
if date[1] < date then begin
   newday=true;
end;

// Yesterday High crosses enough and its a new day
if 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;

// Stops
setexitonclose;


#2 posted 09 Mar 2012 
User avatar

Status: Offline
Posts: 5180
Thanks Received: 1424 times
Thanks Given: 856 times
Joined: 29 Aug 2006
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?


#3 posted 09 Mar 2012 

Status: Offline
Posts: 62
Thanks Received: 1 time
Thanks Given: 7 times
Joined: 08 Feb 2012
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]
Downloaded 40 times
#4 posted 09 Mar 2012 
User avatar

Status: Offline
Posts: 5180
Thanks Received: 1424 times
Thanks Given: 856 times
Joined: 29 Aug 2006
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.



For this message the author TJ has received thanks:
JoshM


#5 posted 10 Mar 2012 

Status: Offline
Posts: 523
Thanks Received: 200 times
Thanks Given: 299 times
Joined: 09 Apr 2010
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.


#6 posted 10 Mar 2012 

Status: Offline
Posts: 62
Thanks Received: 1 time
Thanks Given: 7 times
Joined: 08 Feb 2012
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:
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 day
if 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;

// Stops
setprofittarget(profitstop);
setexitonclose;



Post new topic Reply to topic