Need help for creating the 200MA_System

#1
Dear Traders,

my trading idea is to create a system for long-term end-of-day-trading.
I want to create a better system then buy and hold!

The base or the portfolio should be for example the Dow Jones Industrial Index with 30 stocks.

Rules: BUY

If the 200day moving averages of 20 out of 30 stocks of the Dow are rising and the closing price is above MA 200 -- its a buy

Rules: SELL

If 15 or more stocks are trading below the 200day moving average it is a sell.

The buy and sell signal for this system should be visible in the dow jones index.

I don`t know how to start ! Is it possible to create a system with all these rules or do I have to a Scan or do I need the explorer for.

Thanks for your help ! and don`t worry about my written english!!

MASIEGP
 
Last edited:
#2
What is the software you plan to use? How do you plan to get the EoD data?

You can use Microsoft Excel or any spreadsheet. Writing the formula for you system in spreadsheet is possible.

You will have to copy-paste the closing/EoD price of your chosen 30 scrip in the spreadsheet.

To start with you will need more than 200 days of data . . . (aprox 1 year)

If you plan to back-test your idea for 'n' years then you will need data for n+1 years.

Best Wishes


.
 

KelvinHand

Well-Known Member
#5
Hello Amibroker_Fans,

Could anybody give me a helping hand how to do this project ?

Thanks in advance !

Regards

masiegp
Here is the 1st draft project:

1. Put all the Dow Jones Industrial Index with 30 stocks into a watch list.
2. Do a exploration script to scan:
Buy= C>MA(C, 200)
Sell = C<MA(C, 200)
Filter = (Buy or Sell) and V>0;

3. Do the Exploration On the watchlist on item 1

That it.
You can find with is DJI stock above or below 200MA.
You can manually count how many Buy vs Sell in the DJI.


With this Buy vs Sell scenario.
Then you can scan other stock not in the DJI watchlist.

After you familiarize with all these, go for review. fine tune your requirement

then goto project phase B.
 
#6
Hello KelvinHand,

Thanks for reply.

Condition1 for Buy is C > MA(C,200)
Condition 2 for Buy is todays value for MA200 greater than one day ago.

Opposite for SELL


Please tell me the afl for that condition.

next step:

I need the number of stocks which are in buy modus if the number ist greater then 20 out of 30 I want to get a signal in the Down Jones Index
Buy - next day open

vice versa SELL

iS IT POSSIBLE TO DO THAT IN ONLY ONE AFL-CODE ?

Thanks
 
#7
Thanks for reply !

I want to do with amibroker - and therefore I need the afl-code !

Thanks
First do what kelvin has told above, then try this

Code:
//The system definitions for Buy / Sell 
m = MA(C, 200);
Buy = C > m and m > Ref(m,-1); // Close is above MA and MA is rising :)
Sell = C < m and m < Ref(m,-1); // Close is below MA and MA is falling :)

// the following line uses Flip function to get "1" after the buy signal and reset it back to "0" after sell appears.

in_trade = flip( buy, sell );

//Then we add regular AddToComposite part:

AddToComposite( in_trade, "~BullishCount", "V" );

//this uses "~BullishCount" artificial ticker to store the results. 
//run just Scan of the formula and the "~BullishCount" ticker would become available.

// After that if you need to plot can use

graph0 = foreign( "~OpenPosCount", "V");

:) Happy
 

mastermind007

Well-Known Member
#8
First do what kelvin has told above, then try this
Happy and masiegp

Single line correction in Happy's Version

It is better to keep two flip signals, one for each direction. Sooner or later, you will add filters which from a coding POV means that your single flag will not be enough.

Code:
in_long_trade = flip( buy, sell );
in_short_trade = flip( sell, buy );
 

KelvinHand

Well-Known Member
#9
Hello KelvinHand,

Thanks for reply.

Condition1 for Buy is C > MA(C,200)
Condition 2 for Buy is todays value for MA200 greater than one day ago.

Opposite for SELL


Please tell me the afl for that condition.

next step:

I need the number of stocks which are in buy modus if the number ist greater then 20 out of 30 I want to get a signal in the Down Jones Index
Buy - next day open

vice versa SELL

iS IT POSSIBLE TO DO THAT IN ONLY ONE AFL-CODE ?

Thanks
You see. You started something without clear requirements.
How can people help you.

Once i draft the project, you started to pore in information

possibility or not, need to see the on-going direction.

You need to do the manual exploration 1st, so that you had the basis of data collection of what you intend to do to show us.
Otherwise, you keep plug the idea from the air, we keep doing the code to and fro, that will be very tiring.
 
Last edited:

KelvinHand

Well-Known Member
#10
Here is the sample exploration.
PHP:
MA1  = MA(C, 200);
MA1_1 = Ref(MA1,-1);

Buy = C>MA1 AND MA1>MA1_1;
Sell =C<MA1 AND MA1<MA1_1;

Filter = (Buy OR Sell) AND V>0; 

SetOption("NoDefaultColumns", True );
AddTextColumn( Name(), "Ticker",1, colorDefault,colorDefault, 55);
AddTextColumn( FullName(), "Stock",1, colorDefault,colorDefault,222);
AddColumn( DateTime(), "Date", formatDateTime, colorDefault,colorDefault, 77 );
AddColumn( IIf( Buy, 66, 83 ), "Trade", formatChar, colorDefault,colorDefault,22 ); 
AddColumn(C, "Close", 1.3, colorDefault, colorDefault, 68);
AddColumn(V, "Volume", 1.0, colorDefault,colorDefault, 77);

Setup your watchlist as DJI for Dow Jones Index
Before run exploration, "define the filter" (small icon after the "Apply to:") to your watchlist DJI and "Range:" 1 recent day(s)

The watchlist is very important for the script development.
Without that, you can forget the project.
 
Last edited:

Similar threads