Exploring a simple scriptI decided that I want to talk about something that I have been working on for the last year, and after attending a seminar over the weekend, I decided to just do it. Someone said something to me that really stuck. I am going to paraphrase it, but here it is. You can give people whatever they want and very few of them are going to use it or be satisfied with it.
So in that spirit, I am going to share a script that I worked on for better part of a year. It isn’t a wildly profitable script but it has a lot of elements in it that can be applied to many other scripts and will teach you a lot about scripting.I’ll post it here in its entirety, and then over the next few days I’ll break down each part so you can see what I did. I had some help with the script, and thank those that helped.The first thing I’ll talk about is the code in Red. I created this so that the variables in the list could be switched out and tested. In this script I tested a cross of two EMA’s for an open and a close condition. However if I wanted to test how a different MA cross would work I could simply switch out the EMA’s and WMA’s for a different MAThis allows me to make a lot of changes on the fly without screwing with the heart of the **script. Here is the script with original EMA’s and WMA’sHere is a chart with a HMA substituted for the WMA’s
//Adjust these Variables as neededBuyTakeProfit Point(100)SellTakeProfit Point(100)BuyStopLoss Point(100)SellStopLoss Point(100)Local ECA = EMA[0](Close, 1)Local ECB = WMA[0](Close, 3)Local XCA = EMA[0](Close, 10)Local XCB = WMA[0](Close, 34)
Normal 0 false false false EN-US X-NONE X-NONE
global int ii
global int hh
global lastBreakPrice
global lastBreakPriceBS //the lastBreakPrice with buy/sell action
global int buysellzone //-1 sell zone; 1 buy zone; replace getValue("4 hr. 40 day", issellposition)
//approximate 4 hour BB breakout
if (High[0]>= BLG_U[0](Close, 80, 2)) then
buysellzone=-1
lastBreakPrice=high[1]
endif
if (Low[0]<= BLG_L[0](Close, 80, 2)) then buysellzone=1 lastBreakPrice=low[1] endif //crossover if buysellzone=-1 and lastBreakPricelastBreakPriceBS and CrossDown(ECA , ECB) and ECA < lastbreakpricebs="lastBreakPrice" ii="ii+1" buysellzone="1"> BLG_L[0](Close, 80, 2)) then
AddBuyEntry
lastBreakPriceBS=lastBreakPrice
hh=hh+1
ENDIF
if isbuyposition then
addbuyexit BElOW = lastBreakPriceBS - Point(0))
endif
if issellposition then
addsellexit OVER = lastBreakPriceBS+ Point(0))
endif
if isbuyposition and
CrossDown( XCA, XCB) then
addbuyexit
endif
if issellposition and
CrossUp( XCA, XCB) then
addsellexit
endif
0 التعليقات:
أنشر تعليقك