⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reaction trend system.afl

📁 一个更精度的平滑涵数, 可用于股票交易系统.用于Amibroker 平台
💻 AFL
📖 第 1 页 / 共 3 页
字号:
					// just change mode, we are short already
					reaction_position_short = 0;
					trend_position_short = 1;
					tpss[ i ] = 1;
				
				}
			
			}
			
			// price never enters the sell area
			if (H[ i ] < S1[ i ] AND L[ i ] > LBOP[ i ] AND timebar[ i ] == 1) {
					// cover at close
					Sell[ i ] = 1;
					SellPrice[ i ] = C[ i ];
					reaction_position_buy = 0;
					
			} else
				
			// price enters area 4
			if (L[ i ] <= LBOP[ i ]) {
				
				// sell long position
				Sell[ i ] = 1;
				SellPrice[ i ] = LBOP[ i ];
				reaction_position_buy = 0;
				
				// go short in trend mode
				Short[ i ] = 1;
				ShortPrice[ i ] = LBOP[ i ];
				trend_position_short = 1;
				tpss[ i ] = 1;
				
			}	
			
		
		} else
		
		
		// open in area 2
		if (O[ i ] >= S1[ i ] AND O[ i ] < HBOP[ i ]) {
		
			// sell position straight away
			Sell[ i ] = 1;
			SellPrice[ i ] = O[ i ];
			reaction_position_buy = 0;
			
			// and reverse
			Short[ i ] = 1;
			ShortPrice[ i ] = O[ i ];
			reaction_position_short = 1;
				
			// enter area 3
			if (H[ i ] >= HBOP[ i ]) {
				
				// close out short position
				Cover[ i ] = 1;
				CoverPrice[ i ] = HBOP[ i ];
				reaction_position_short = 0;
				
				// go long in trend mode
				Buy[ i ] = 1;
				BuyPrice[ i ] = HBOP[ i ];
				trend_position_buy = 1;
				tpsl[ i ] = 1;
				
			} else
				
			// enter area 4
			if (L[i ] <= LBOP[ i ]) {
				
				// just change mode, we are short already
				reaction_position_short = 0;
				trend_position_short = 1;
				tpss[ i ] = 1;
				
			}			
		
		} else		
		
		// open in area 3
		if (O[ i ] >= HBOP[ i ]) {
		
			// position is already long, just change the mode
			reaction_position_buy = 0;
			trend_position_buy = 1;	
			tpsl[ i ] = 1;
		
		} else				
				
		// open in area 4
		if (O[ i ] <= LBOP[ i ]) {
			
			// close the long position
			Sell[ i ] = 1;
			SellPrice[ i ] = O[ i ];
			reaction_position_buy = 0;
			
			// and go short in trend mode
			Short[ i ] = 1;
			ShortPrice[ i ] = O[ i ];
			trend_position_short = 1;
			tpss[ i ] = 1;
		
		}
		
	} else
			
	/* long trend mode position, exit at the trailing stop, 4 entry areas of interest
	1) open between trailstop_long and HBOP (area 1)
	2) open between trailstop_long and LBOP (area 2)
	3) open above HBOP (area 3)
	4) open below LBOP (area 4)
	*/
	if ( (phase_arr[ i ] == 1 OR phase_arr[ i ] == 2 OR phase_arr[ i ] == 3) AND 
			reaction_position_buy == 0 AND trend_position_buy == 1 AND 
			reaction_position_short == 0 AND trend_position_short == 0) {	
		


		// open in area 1
		if (O[ i ] > trailstop_long[ i ] AND O[ i ] < HBOP[ i ]) {
		
			// enter area 2
			if (L[ i ] <= trailstop_long[ i ]) {
			
				// long position in trend mode is stopped out
				Sell[ i ] = 1;
				SellPrice[ i ] = trailstop_long[ i ];
				trend_position_buy = 0;
				
				// enter area 4
				if (L[ i ] <= LBOP[ i ]) {
				
					Short[ i ] = 1;
					ShortPrice[ i ] = LBOP[ i ];
					trend_position_short = 1;
					tpss[ i ] = 1;
				
				} 				
			
			} 
			
			// enter area 3 **** nothing done here
		
		} else
		
		// open in area 2
		if (O[ i ] <= trailstop_long[ i ] AND O[ i ] > LBOP[ i ]) {
		
			// long position in trend mode is stopped out at the open
			Sell[ i ] = 1;
			SellPrice[ i ] = O[ i ];
			trend_position_buy = 0;
			
			// enter area 4
			if (L[ i ] <= LBOP[ i ]) {
			
				// take a short position
				Short[ i ] = 1;
				ShortPrice[ i ] = LBOP[ i ];
				trend_position_short = 1;
				tpss[ i ] = 1;
			
			} else
			
			// enter area 3
			if (H[ i ] >= HBOP[ i ]) {
			
				Buy[ i ] = 1;
				BuyPrice[ i ] = HBOP[ i ];
				trend_position_buy = 1;
				tpsl[ i ] = 1;
			
			}
		
		} else
		

		// open in area 3 *** nothing done here

		
		// open in area 4
		if (O[ i ] <= LBOP[ i ]) {
		
			// sell the long position
			Sell[ i ] = 1;
			SellPrice[ i ] = O[ i ];
			trend_position_buy = 0;
		
			// now go short in trend mode
			Short[ i ] = 1;
			ShortPrice[ i ] = LBOP[ i ];
			trend_position_short = 1;
			tpss[ i ] = 1;
		
		}
		
	} else
	
	/* short trend mode position, exit at the trailing stop, 4 entry areas of interest
	1) open between LBOP and trailstop_short (area 1)
	2) open between trailstop_short and HBOP (area 2)
	3) open below LBOP (area 3)
	4) open above HBOP (area 4)
	*/
	if ( (phase_arr[ i ] == 1 OR phase_arr[ i ] == 2 OR phase_arr[ i ] == 3) AND 
			reaction_position_buy == 0 AND trend_position_buy == 0 AND 
			reaction_position_short == 0 AND trend_position_short == 1) {	
		
		
		// open in area 1
		if (O[ i ] < trailstop_short[ i ] AND O[ i ] > LBOP[ i ]) {
		
			// entry of area 2
			if (H[ i ] >= trailstop_short[ i ]) {
			
				// cover short position, short trend mode is stopped out
				Cover[ i ] = 1;
				CoverPrice[ i ] = trailstop_short[ i ];
				trend_position_short = 0;
				
				// enter are 4
				if (H[ i ] >= HBOP[ i ]) {
				
					// enter long position
					Buy[ i ] = 1;
					BuyPrice[ i ] = HBOP[ i ];
					trend_position_buy = 1;
					tpsl[ i ] = 1;
				
				}
			
			} 
			

			// entry of area 3 *** nothing done here

		
		} else
		
		// open in area 2
		if (O[ i ] >= trailstop_short[ i ] AND O[ i ] < HBOP[ i ]) {
		
			// cover short position, stopped
			Cover[ i ] = 1;
			CoverPrice[ i ] = O[ i ];
			trend_position_short = 0;
			
			// enter area 4
			if (H[ i ] >= HBOP[ i ]) {
			
				// go long
				Buy[ i ] = 1;
				BuyPrice[ i ] = HBOP[ i ];
				trend_position_buy = 1;
				tpsl[ i ] = 1;
			
			} else
			
			// enter area 3
			if (L[ i ] <= LBOP[ i ]) {
			
				// go short
				Short[ i ] = 1;
				ShortPrice[ i ] = LBOP[ i ];
				trend_position_short = 1;
				tpss[ i ] = 1;
			
			}
		
		} else
		

		// open in area 3 *** nothing done here

		
		// open in area 4
		if (O[ i ] >= HBOP[ i ]) {
		
			// cover short position
			Cover[ i ] = 1;
			CoverPrice[ i ] = O[ i ];
			trend_position_short = 0;
			
			// go long
			Buy[ i ] = 1;
			BuyPrice[ i ] = O[ i ];
			trend_position_buy = 1;
			tpsl[ i ] = 1;
		
		}
		
	}

	// *** extra code that is needed for intraday data ***	
	// "B" day PLUS LONG reaction mode position. 3 Entry areas of interest
	//1) open between LBOP and HBOP (area 1)
	//2) open below LBOP (area 2)
	//3) open above HBOP (area 3)
	
	//check for outbreak on "B" day having a long position
	
	if (phase_arr[ i ] == 1 AND reaction_position_buy == 1 AND trend_position_buy == 0 AND 
				reaction_position_short == 0 AND trend_position_short == 0) {
	
		// open in area 1
		if (O[ i ] > LBOP[ i ] AND O[ i ] < HBOP[ i ]) {
		
			// enter area 2
			if (L[ i ] <= LBOP[ i ]) {
			
				// sell long position
				Sell[ i ] = 1;
				SellPrice[ i ] = LBOP[ i ];
				reaction_position_buy = 0;
				
				// go short in trend mode
				Short[ i ] = 1;
				ShortPrice[ i ] = LBOP[ i ];
				trend_position_short = 1;
				tpss[ i ] =1;
				
			} else
			
			// enter area 3
			if (H[ i ] >= HBOP[ i ]) {
			
				reaction_position_buy = 0;
				trend_position_buy = 1;
				tpsl[ i ] = 1;
			
			}
			
		} else
		
		// open in area 2
		if (O[ i ] <= LBOP[ i ]) {
		
			// sell long position
			Sell[ i ] = 1;
			SellPrice[ i ] = O[ i ];
			reaction_position_buy = 0;
				
			// go short in trend mode
			Short[ i ] = 1;
			ShortPrice[ i ] = O[ i ];
			trend_position_short = 1;
			tpss[ i ] = 1;
		
		} else
		
		// open in area 3
		if (O[ i ] >= HBOP[ i ]) {
		
			// only change the mode
			reaction_position_buy = 0;
			trend_position_buy = 1;
			tpsl[ i ] = 1;
		
		}
				
		
	} else	
	
	// *** extra code that is needed for intraday data ***	
	// "S" day PLUS SHORT reaction mode position. 3 Entry areas of interest
	//1) open between LBOP and HBOP (area 1)
	//2) open below LBOP (area 2)
	//3) open above HBOP (area 3)
	
	//check for outbreak on "S" day having a short position
	
	if (phase_arr[ i ] == 3 AND reaction_position_buy == 0 AND trend_position_buy == 0 AND 
				reaction_position_short == 1 AND trend_position_short == 0) {	
				
		// open in area 1
		if (O[ i ] > LBOP[ i ] AND O[ i ] < HBOP[ i ]) {
		
			// enter area 2
			if (L[ i ] <= LBOP[ i ]) {
			
				// change mode only
				reaction_position_short = 0;
				trend_position_short = 1;
				tpss[ i ] = 1;

				
			} else
			
			// enter area 3
			if (H[ i ] >= HBOP[ i ]) {
			
				// cover short position
				Cover[ i ] = 1;
				CoverPrice[ i ] = HBOP[ i ];
				reaction_position_short = 0;
				
				// go long in trend mode
				Buy[ i ] = 1;
				BuyPrice[ i ] = HBOP[ i ];
				trend_position_buy = 1;
				tpsl[ i ] = 1;
			
			}
			
		} else	
		
		// open in area 2
		if (O[ i ] <= LBOP[ i ]) {

			// only change the mode
			reaction_position_short = 0;
			trend_position_short = 1;
			tpss[ i ] = 1;
		
		} else
		
		// open in area 3
		if (O[ i ] >= HBOP[ i ]) {

			// cover short position
			Cover[ i ] = 1;
			CoverPrice[ i ] = O[ i ];
			reaction_position_short = 0;
				
			// go long in trend mode
			Buy[ i ] = 1;
			BuyPrice[ i ] = O[ i ];
			trend_position_buy = 1;
			tpsl[ i ] = 1;
		
		}		
				
	}
	
	
}



// --------------------------------------

// For Chart 
Plot(C,"",1,64);

// define title
Title=Name()+ ",  O: "+WriteVal(O)+ ",  H: "+WriteVal(H)+ ",  L: "+WriteVal(L)+ ",  C: "+WriteVal(C) +
EncodeColor( colorOrange ) + ",  HBOP: " + EncodeColor( colorWhite ) + WriteVal(HBOP) +
EncodeColor( colorRed ) + ",  S1: " + EncodeColor( colorWhite ) + WriteVal(HBOP) +
EncodeColor( colorBrightGreen ) + ",  B1: " + EncodeColor( colorWhite ) + WriteVal(HBOP) +
EncodeColor( colorGreen ) + ",  LBOP: " + EncodeColor( colorWhite ) + WriteVal(HBOP);

// buy, sell, short and cover symbols
PlotShapes(shapeUpArrow*Buy,colorWhite,0,BuyPrice,0);
PlotShapes(shapeDownArrow*Sell,colorYellow,0,SellPrice,0);
PlotShapes(shapeHollowDownArrow*Short,colorYellow,0,ShortPrice,-15);
PlotShapes(shapeHollowUpArrow*Cover,colorWhite,0,CoverPrice,-15);

// triagle show breakouts 
PlotShapes(shapeUpTriangle*tpsl,colorWhite,0,BuyPrice,0);
PlotShapes(shapeDownTriangle*tpss,colorYellow,0,ShortPrice,-15);

// 1 = "B" day, 2 = "O" day, 3 = "S" day
PlotShapes(shapeDigit1 * (hlp_phase == 1),IIF(hlp_b == 1,colorYellow,colorWhite),0, HBOP,0);
PlotShapes(shapeDigit2 * (hlp_phase == 2),colorWhite,0, HBOP,0);
PlotShapes(shapeDigit3 * (hlp_phase == 3),IIF(hlp_s == 1,colorYellow,colorWhite),0, HBOP,0);

// lightblue digits at days where original phase is used for the calculation.
PlotShapes(shapeDigit1 * (hlp_phase_l1 == 1),colorLightBlue,0, HBOP,-15);
PlotShapes(shapeDigit3 * (hlp_phase_l1 == 3),colorLightBlue,0, HBOP,-15);

// draw levels
Plot(B1,"",colorBrightGreen,1);
Plot(S1,"",colorRed,1);
Plot(HBOP,"",colorOrange,1);
Plot(LBOP,"",colorGreen,1);

// for analysis purposes
Filter = 1;
AddColumn(phase_arr,"Phase");
Addcolumn(LBOP,"LBOP");
AddColumn(O,"O");
AddColumn(buy,"buy");
AddColumn(sell,"sell");
AddColumn(short,"short");
AddColumn(cover,"cover");
AddColumn(tpsl,"tpsl");
AddColumn(tpss,"tpss");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -