Mike Fishy and Automation System Programming (Bots)


#264

You can click the buttons on your screen if you load the app on an Android emulator.


#265

Wow… really like the idea… It would be great to give our bot a summary screen where we could for example terminate it with a click or see a summary of how it is doing remotely.

If I could see how my bot was doing on my phone from home that would be most amazing, with the ability to stop it if it was doing something I wasnt wanting. How cool would that be.

My struggle with PHP continues.

Crash.


#266

That did the trick @ly0009 and I also turned off notifications @Crash101 ! Thank you all! Now I have some catching up to do :sweat_smile:


#267

Windows would be nice. I wonder if having it connected to an app for mobile with a few simple functions like a stop all command in case of a major problem. Push notifications and performance charts would be nice to keep track.
I ask because some people travel for work lots and cannot be at their computer for extended periods of time. Making a way to keep track of such a program and having an ability to shut it down remotely would be nice. This also may be an easy way to push bug reports.
I don’t much about much so i hope i made some sense. Please let me know if this is plausible or laughable, i can handle both. Thanks.


#268

Haha i see now as i made it to the end that this has been asked already.


#269

I am just waiting for the first push notification from the app. App has option for email and superSMS (override phones silent setting) etc. It is sent for dummy trading on Binance at the moment.

I can also ask user to confirm each trade in the app etc. Not coded this yet but easy enough.


#270


#271

Damn this thread is amazing and filled with brainiacs! Much respect :clinking_glasses: :beers: By seeing the code’s logic, it actually helps me understand a trader’s thought process. Just a thought, is there a $tick . “volume” to filter out ( $dontbuy ) low liquidity coins to prevent getting stuck with a dud (in the event we have to emergency-stop the bot?

Or maybe in addition to the above, I would manually add coins/tokens like NPXS & HOT to @Mike_Fishy 's $dontbuy list… ie: if you look at NPXS and HOT they always have high daily-volumes… but it’s like one coin-at-a-time speed (bad liquidity).


#272

Hi all,

OK, just caught up on all the messages.

  1. Github - was going to do this, but since someone else has done it, they get to own it :slight_smile:
    (Number one rule of Programmers, you make it, you own it)

  2. Rule set is far to basic yet to be used for production, it needs much more.

  3. Love the mobile ideas, great job. If you are going to use a name, just use something simple and doesn’t tie to anyone, like “Thepubbot” or something with maybe a link this this site. Trust me, people are going to find the code on Github, so all the “use at your own risk” stuff needs to be on that page and we should probably start a wiki in Github as well.

  4. Volume has not been added yet, it is a separate API call, just trying to keep things simple now so you can get use to the ideas, then once you have had time to play with it and see it’s faults, you then get to understand the next rule sets and why they are needed. Just remember, a human trader doesn’t quite work the same as a Bot. A Bot can work really quite differently as it is not an individual, it’s a team. Start thinking of the bot being a team of people and you will start understanding the right way to code.

  5. If you are having problems with PHP or other executables on Windows, it probably needs the C++ Runtimes which may be downloaded from Microsoft. Also check the main PHP.net page for any useful information on installing.

  6. It’s PHP for now as the language is easy and can run on many platforms. We can easily change it to another language as PHP is quite similar to C++ (which is why I use PHP to create prototypes). Also, if you want to run it in the cloud, it will happily run on even the most basic Linux server.
    https://www.vultr.com/pricing/
    $2.50 a month server will run it adequately and if you want some help setting one up, let me know. Though later on when we add a lot more logic, the $5/month one may be needed.
    I am not affiliated with Vultr, I do use their servers though for my personal projects. If you hunt around, you could probably even find a free one.

  7. Lastly, I want to thank you all for making the effort, that is what a community is about.

Please understand, code needs to be iterated on often, it is like a living document. It is going to have problems and will need fixes and changes. We need to tell it how to avoid pump and dumps and train it to execute only realistic trades. So much is taken for granted when you look at a chart as the human brain is capable of processing data without knowing any rules. Code is different, but if you feel like it, we can play with an AI Engine and use Machine Learning algorithms on the data, there is no limit to what a community of people can do. Even if you are not a programmer, still need people to test, still need people to extract data from this thread and write up wiki pages, still need other tasks as well, everyone can contribute.

But most important of all…

Stay Fishy


#273

Not a bother Brother!!

Nice to have your input. This is going to be a great group of people. Lets get building.

Crash


#274

May I have your github account @Mike_Fishy so I can add you as an administrator ?
@mwlang you can also be an administrator if you want ?

I can also add others collaborators if someone wants ?

We’ll need people to maintain the repo in a good shape ! :slight_smile:


#275

Mike,

I have been looking at the Rsi logic and I found it a bit mind warping.

Does the idea for a function work for something like this? We can build functions to work out the relevant historic indicators of whatever we want to use. Then we simply pull the function into the larger loop. Does this work in php? This is what I would do in VBA. I tend to make functions of functions and then call them as necessary.

Just a thought and I am still not with that RSI logic yet. I will get there. Been learning lots on php and am understanding more all the time.

I made a code that read and printed all the tickers, counted and put into a new array the tickers with USDT in it. So we are getting there. I got the hang of $($ticker. blah) did my head in to understand why two $ but figured that out and I nearly have a certificate in php programming from solo learn.

https://www.sololearn.com/Play/PHP

Might be useful for others here.

Crash


#276

The RSI logic is not perfect, it is actually slightly modified to work in a more useful manner for the bot.
(it is also only RSI Step 1)

However, if you wish to understand RSI, the best thing I can recommend is:

In the PHP code where I used $tick to create arrays, it is actually creating multiple different array names using the variable as a leading part of the array name. This is how you can initialise arrays using a variable which changes. It actually creates about 50 arrays with only a small amount of code, otherwise it would need each one spelt out and we do not always know up front if Binance have added or removed any.

I should mention, any other algorithms you want to include from Investopedia, let me know. It is also a good reference for learning about trading. Also, there should be an array created for storing the RSI value to calculate the RSI trend.

One other thing, the bot doesn’t have to sell something just because the TA suggest it is time to sell, you can program the bot to HODL for the right opportunity or Stop Loss out if it hits a threshold.

I invite you all to take a few minutes and watch this guy:

Trading is very much a Casino, the worlds biggest legal Casino. Our job is to program the bot to stack things in our favour, so you should think about this when you think about what the bot rules should be.

Edit: will create a new Github account to keep it separate from my existing private account.
Have created - Github account is: mfishybot
Drop me an invite - thanks.

Cheers…

Mike Fishy


#277

Mike,

This guy is truly inspiring. I give that pitch to anyone that thinks crypto currency is gambling. I have given this approach at work to some disbelievers and it works.

Nice One!!


#278

Level2:


#279

My github is, surprise, surprise, “mwlang” :rofl:


#280

This raises a point I’d like to open. I’ve been following along, running the scripts as you put 'em out and modifying with just some simple tweaks, like trying to do a stop/loss. One of the first things that strikes me is that we don’t assemble the data into open, high, low, close for an N timeframe candles and thus “periods” in the traditional sense, so it really boils down to understanding the math behind candlesticks in order to decompose into a streamed way of processing that data as you’re doing.

I should say here, kudos to really breaking the data down to it’s bare minimum – that’s some brilliance there, or maybe just highlighting many years of experience automating trading systems, but yeah, definitely a big leap in understanding how things are working here and how that relates back to what most of us know and understand with the standard indicators. So that’s the main struggle I have – i.e. translating what you’ve done back to more well documented world of charting as I’ve learned over the last 12 months or so.

Instead of candles, you’re just processing price data as it flows in and you keep, what is effectively, three “periods” worth of data with the short, medium, and long trend arrays. So, when long trend is 280 entries in the array, that’s effectively 56 minutes.

This is where it gets tricky for me, because if one goes and changes the duration of short, med, and long durations, it has an effect on the RSI that gets calculated (also has an effect on the spreads). So it starts to become a lot of hidden traps as well as lots of variables playing into the whole dynamic.

With the replay option I built earlier, it quickly became obvious to me that I am hard-pressed to find a winning combination of LT, MT, ST durations, spread threshold, and RSI threshold to find the sweet spot…and of course, as we all know, with the market dynamics changing so rapidly in cryptos, it seems to me the natural course of action is to start to make these parameters self-adaptive to the changing market parameters. I guess I’m jumping to Chapter 10 when you’re barely halfway through Chapter 2 and that’s ok – not so much seeking a solution to my struggles as just sharing my personal challenges and learnings.

BTW, you’re doing something really nice with that buy_flag and I’ve come to think of this little flag as a gateway guard that takes you from one phase to the next…here’s how I read 'em (and maybe this helps others understand):

“BUY READY” means, we’re not only waiting to buy, we’re waiting definitively for the next “bottom” to come around. To do that, we have to wait for price to go UP, then DOWN, then next time it goes UP, we know we’re at a “local bottom”. BUY READY sets the stage to wait for next UP cycle.

“BUY PREP” - When price starts going UP, we’re in an uptrend, but we don’t know how close to the last bottom, so ride along until we reach the top and start going down again. If it goes down hard enough (as measured by the spread), then we have a potential winning setup at the next bottom. If it’s kinda weak/flat (as a low spread will indicate), we haven’t really driven down hard enough to have a good bounce up.

“BUY ORDER” - we’re going down hard enough that a good bounce up is likely, so in this state we wait for the downward trend to reverse and start going UP AND for the RSI to be relatively low, further indicating there’s room to grow (i.e. bounce).

“SELL READY” – simply wait for the trend to reverse and start going down and sell.

“SELL DONE” – record the complete buy/sell cycle and start us back at the beginning at “BUY READY”

So, if I’ve got this reasoning right, then that leads to wondering…

If we’re selling and thus ending the cycle, doesn’t that also mean we’re effectively back to “BUY PREP” instead of “BUY READY”?

If I implement a STOP LOSS and it triggers, effectively saying I bet wrong this time and we’re in downtrend, should I be going back to “BUY ORDER” state and waiting for trend to reverse back UP instead of all the way to BUY READY?

In both of the two above, it just feels like what can effectively happen by going back to BUY READY, is we miss a cycle or two as we ride UP, then DOWN, then prepare to buy again.


#281

Gold Star, you are way ahead on the curve :slight_smile:

Yes, the variables need to be adaptive and individual to each trading pair, not global.

If a successful and profitable trade was done, what do charts normally look like after that?
(why shouldn’t we go back to step 1? After a good trade, things tend to go quiet or backwards again)

If you did a stop loss, shouldn’t you really go back to step 1?
(as things might need to change to correct the action that was taken).

There is always more trade opportunities, you shouldn’t try and go for every one of them, rather pick the opportunities that are most likely to provide a successful outcome.

The script done in this way, helps everyone to identify all the stuff that needs to be catered for. It is that hands on experience and seeing all the stuff that goes wrong, that will make you think better.

Go back to the beginning of this thread on March 30th, where I described the Autobots. I think you are this far ahead now that if you go back and read that, you will understand why it was done that way. The best system has a “Monarch” that oversees all it’s “Subjects”, with an Ambulance around to recover things when one or more of the “Subjects” gets broken. If the Monarch breaks, the whole system should be restarted.

You have now reached the point where you realise a single script isn’t going to cut it :slight_smile:

Stay Fishy


#282

Updated Code for you guys to play with:

<?php
require 'vendor/autoload.php';

// This bot will trade USDT to the other pairs and back to make more USDT
// It shall use all the trading pairs to make more UDST except the ones we tell it not to use

$strend = 60;             // Short Term Trend - must be less than $mtrend
$mtrend = 100;            // Medium Term Trend - must be less than $ltrend
$ltrend = 240;            // Long Term Trend
$tradefile = "USDT.txt";  // The Trade Logging file name
$minspread = 1;           // The minimum spread percentage needed for a trade
$minrsi = 48;             // Relative Strength must be below this number to buy
$sellbuffer = 1.02;       // Create a buffer to hold CDA if sell is not profitable (2% profit threshold)
$stoplossbuffer = 0.99;   // Stop Loss buffer to sell CDA if it is forming a loss (1% Stop Loss threshold)

// Do not change any of the flags, we use this to signal the bot what to do and when
$buyready = 0;            // This flag signals the bot that the pair meets rules to buy
$buyprep = 1;             // This flag signals the bot to prepare to buy
$buyord = 2;              // This flag signals the bot to place an order
$sellok = 3;              // This flag signals the bot that the order was completed
$sellready = 4;           // This flag signals the bot to sell
$selldone = 5;            // This flag signals the bot the trade completed
$dontbuy = 6;             // This flag signals the bot we dont want to trade BCASH :P

// Standard variables and arrays we use
$i = 0;
$binance_prices = array();
$time_start = time();
$time_end = 0;
$run_time = 0;
$rpc = 0;
$tpc = 0;
$q = 0;

// API call to fetch pricing data from Binance
function getprices()
{
	$api = new Binance\API("<api key>","<secret>");
	$mp = $api->prices();
	return $mp;
}

// Start of the Loop - can run for months - press CTRL-C to stop
for($i = 0; $i <= 2000000; $i++)
{
	$time_end = time();
	$run_time = round((($time_end - $time_start)/60),2);
	print "====================================\n";
	print "Iteration = $i \n";
	print "Running Time: $run_time mins \n";
	print "Current running percentage = $rpc \n";
	print "====================================\n";

	// Fetch current prices from Binance
	$binance_prices = getprices();

	// Loop through the price data as key and value pairs
	foreach($binance_prices as $key => $value)
	{

		// Only process pairs with USDT
		if(strpos($key, "USDT"))
		{

			// Convert the pair name to lower case in varibale $tick
			// for example the name "BTCUSDT" will become "btcusdt"

			$tick = strtolower($key);

			// For the first iteration, create arrays and varibales for the bot
			if($i == 0)
			{

				// Use the lower case name to form the leading part of varibales and arrays
				// for exmaple, using "btcusdt" and adding "st" for the short term array
				// will initialise an array called "btcusdtst"
				// as we loop thorugh the pairs, each one gets created for each pair
				// for exmaple "NEOUSDT" will become "neousdtst"

				${$tick . "st"} = array();         // Short Term Array
				${$tick . "mt"} = array();         // Medium Term Array
				${$tick . "lt"} = array();         // Long Term Array
				${$tick . "stavg"} = 0;            // Short Term Moving Average
				${$tick . "mtavg"} = 0;            // Medium Term Moving Average
				${$tick . "ltavg"} = 0;            // Long Term Moving Average
				${$tick . "strend"} = 0;           // Short Term Moving Trend
				${$tick . "mtrend"} = 0;           // Medium Term Moving Trend
				${$tick . "ltrend"} = 0;           // Long Term Moving Trend
				${$tick . "lspread"} = 0;          // Long Term Spread
				${$tick . "rsi"} = 0;              // Relative Strength Indicator for this pair
				${$tick . "buyflag"} = $buyready;  // Set this pair to buyready
				${$tick . "buyvalue"} = 0;         // record what we buy for on this pair
				${$tick . "sellvalue"} = 0;        // record what we sell for on this pair
				${$tick . "lasttrade"} = 0;        // record we have had one trade done
				${$tick . "lasttpc"} = 0;          // record what percentage last the trade was
				${$tick . "isset"} = 1;            // used to signal we are initialised for this pair
			}

			// We are not on the first loop anymore, we proceed with processing the data
			else
			{

				// Exclude List - these ones we do not trade

				if($key == "BCHABCUSDT") ${$tick . "buyflag"} = $dontbuy;
				if($key == "BCHSVUSDT") ${$tick . "buyflag"} = $dontbuy;
				if($key == "BCCUSDT") ${$tick . "buyflag"} = $dontbuy;
				if($key == "TUSDUSDT") ${$tick . "buyflag"} = $dontbuy;
				if($key == "VENUSDT") ${$tick . "buyflag"} = $dontbuy;
				if($key == "PAXUSDT") ${$tick . "buyflag"} = $dontbuy;

				// Check if the trading pair has been initialised
				// this covers if Binance add a new trading pair on USDT while we are running
				// if Binance adds new trading pairs while bot is running, we shall
				// ignore them and only use the ones since the bot was started and initialised

				if(isset(${$tick . "isset"}))
				{

					// Push data into arrays and shift arrays once we have enough data
					array_push(${$tick . "st"}, $value);
					array_push(${$tick . "mt"}, $value);
					array_push(${$tick . "lt"}, $value);
					if($i > $strend) array_shift(${$tick . "st"});
					if($i > $mtrend) array_shift(${$tick . "mt"});
					if($i > $ltrend) array_shift(${$tick . "lt"});

					// Wait until we have all the arrays populated with data
					if($i <= $ltrend)
					{
						printf("%-9s",$key);
						print "\t:Loading Arrays with data\n";
					}

					// Arrays are populated, so on with the processing
					else
					{

						// Calculate the Moving Average for the 3 arrays
						${$tick . "stavg"} = round((array_sum(${$tick . "st"})/$strend),8);
						${$tick . "mtavg"} = round((array_sum(${$tick . "mt"})/$mtrend),8);
						${$tick . "ltavg"} = round((array_sum(${$tick . "lt"})/$ltrend),8);

						// Check if the Short Term Trend is trending down, flat or up
						// We use the current price to see if it is above or below the short term moving average
						// We use "1" to signal it is trending down, "2" for flat, "3" for trending up
						if($value < ${$tick . "stavg"}) ${$tick . "strend"} = 1;
						if($value == ${$tick . "stavg"}) ${$tick . "strend"} = 2;
						if($value > ${$tick . "stavg"}) ${$tick . "strend"} = 3;

						// Check if the Medium Term Trend is trending down, flat or up
						// We use the short term moving average to see if it is above or below the medium term moving average
						// We use "1" to signal it is trending down, "2" for flat, "3" for trending up
						if(${$tick . "stavg"} < ${$tick . "mtavg"}) ${$tick . "mtrend"} = 1;
						if(${$tick . "stavg"} == ${$tick . "mtavg"}) ${$tick . "mtrend"} = 2;
						if(${$tick . "stavg"} > ${$tick . "mtavg"}) ${$tick . "mtrend"} = 3;

						// Check if the Long Term Trend is trending down, flat or up
						// We use the medium term moving average to see if it is above or below the long term moving average
						// We use "1" to signal it is trending down, "2" for flat, "3" for trending up
						if(${$tick . "mtavg"} < ${$tick . "ltavg"}) ${$tick . "ltrend"} = 1;
						if(${$tick . "mtavg"} == ${$tick . "ltavg"}) ${$tick . "ltrend"} = 2;
						if(${$tick . "mtavg"} > ${$tick . "ltavg"}) ${$tick . "ltrend"} = 3;

						// Calculate the Medium Term spread, which is the percentage difference between
						// the highest recorded price and the lowest recorded price in the Medium Term Array
						$mlow = min(${$tick . "lt"});
						$mhigh = max(${$tick . "lt"});
						${$tick . "lspread"} = round(((1-($mlow/$mhigh))*100),3);
						
						// Calculate the Relative Strength Indicator on the Long Term Array
						// A Low RSI indicates a buy opportunity
						$rsitck = 0;
						${$tick . "gain"} = array();
						${$tick . "loss"} = array();
						foreach(${$tick . "lt"} as $cdaval)
						{
							if($rsitck == 0)
							{
								$cdagain = 0;
								$cdaloss = 0;
							}
							else
							{
								if($cdaval == $cdaprev)
								{
									$cdagain = 0;
									$cdaloss = 0;
								}
								elseif($cdaval > $cdaprev)
								{
									$cdacalc = $cdaval - $cdaprev;
									$cdagain = number_format($cdacalc,8);
									$cdaloss = 0;
								}
								else
								{
									$cdacalc = $cdaprev - $cdaval;
									$cdaloss = number_format($cdacalc,8);
									$cdagain = 0;
								}
							}
							array_push(${$tick . "gain"}, $cdagain);
							array_push(${$tick . "loss"}, $cdaloss);
							$cdaprev = $cdaval;
							$rsitck++;
						}
						$cdarsgain = (array_sum(${$tick . "gain"})) / $ltrend;
						$cdarsloss = (array_sum(${$tick . "loss"})) / $ltrend;
						if($cdarsloss > 0)
						{
							${$tick . "rsi"} = round(100-(100/(1+($cdarsgain/$cdarsloss))),3);
						}
						else
						{
							${$tick . "rsi"} = 100;
						}

						// Print out what we have so far so we can see what is going on
						printf("%-9s",$key);
						print "\tV:";
						printf("%-14.8F",$value);
						print "\t  ST:";
						printf("%-14.8F",${$tick . "stavg"});
						if(${$tick . "strend"} == 1) printf("%-5s",":DOWN");
						if(${$tick . "strend"} == 2) printf("%-5s",":FLAT");
						if(${$tick . "strend"} == 3) printf("%-5s",":UP");
						print "\t  MT:";
						printf("%-14.8F",${$tick . "mtavg"});
						if(${$tick . "mtrend"} == 1) printf("%-5s",":DOWN");
						if(${$tick . "mtrend"} == 2) printf("%-5s",":FLAT");
						if(${$tick . "mtrend"} == 3) printf("%-5s",":UP");
						print "\t  LT:";
						printf("%-14.8F",${$tick . "ltavg"});
						if(${$tick . "ltrend"} == 1) printf("%-5s",":DOWN");
						if(${$tick . "ltrend"} == 2) printf("%-5s",":FLAT");
						if(${$tick . "ltrend"} == 3) printf("%-5s",":UP");
						print "\t  SPREAD:";
						printf("%-03.3F",${$tick . "lspread"}); 
						print "%\t  RSI:";
						printf("%-06.3F",${$tick . "rsi"});
						if(${$tick . "buyflag"} == $buyready) $cdastatus = "Buy Ready";
						if(${$tick . "buyflag"} == $buyprep) $cdastatus = "Buy Prep";
						if(${$tick . "buyflag"} == $buyord) $cdastatus = "Buy Order";
						if(${$tick . "buyflag"} == $sellok) $cdastatus = "Sell OK";
						if(${$tick . "buyflag"} == $sellready) $cdastatus = "Sell Ready";
						if(${$tick . "buyflag"} == $selldone) $cdastatus = "Sell Done";
						if(${$tick . "buyflag"} == $dontbuy) $cdastatus = "Dont Trade";
						if(${$tick . "buyflag"} == $sellready)
						{
							$ctp = round(((($value - ${$tick . "buyvalue"})/${$tick . "buyvalue"})*100),3);
							print "\t S:$cdastatus \tBV:${$tick . "buyvalue"} CTP:$ctp";
						}
						else
						{
							print "\tS:$cdastatus";
						}
						if(${$tick . "lasttrade"} == 1)
						{
							print "   LastTPC:${$tick . "lasttpc"}";
						}
						print "\n";

						// Trading rules start here
						// ========================

						// CDA is trending up so set to buyprep
						if(${$tick . "buyflag"} == $buyready AND ${$tick . "strend"}==3 AND ${$tick . "mtrend"}==3 AND ${$tick . "ltrend"}==3)
						{
							printf("%-9s",$key);
							print "Was Buyready, now Buyprep V:$value\n";
							${$tick . "buyflag"} = $buyprep;
						}

						// CDA was buyprep, now trending down, set to buyord if reasonable spread
						if(${$tick . "buyflag"} == $buyprep AND ${$tick . "strend"}==1 AND ${$tick . "mtrend"}==1 AND ${$tick . "ltrend"}==1 AND ${$tick . "lspread"} >= $minspread)
						{
							printf("%-9s",$key);
							print "Was Buyprep, now Buyord V:$value\n";
							${$tick . "buyflag"} = $buyord;
						}

						// CDA stopped trending down and is ready to buy
						if(${$tick . "buyflag"} == $buyord AND ${$tick . "strend"}!=1 AND ${$tick . "mtrend"}!=1)
						{
							if(${$tick . "rsi"} <= $minrsi)
							{
								printf("%-9s",$key);
								print "Was Buyord, now Buy V:$value\n";
								// Assume we buy at the current value
								${$tick . "buyvalue"} = $value;
								${$tick . "buyflag"} = $sellok;
								$fh = fopen($tradefile, "a") or die("Cannot open file");
								fwrite($fh, "========================== \n");
								fwrite($fh, "Runtime $run_time \n");
								fwrite($fh, "Buy on $key BV:${$tick . "buyvalue"} \n");
								fwrite($fh, "========================== \n");
								fclose($fh);
							}
							else
							{
								printf("%-9s",$key);
								print "RSI Check not meeting Minimum, resetting back to Buy Prep\n";
								${$tick . "buyflag"} = $buyprep;
							}
						}

						// Buy Order on CDA placed, do order tracking here to make sure order completes
						if(${$tick . "buyflag"} == $sellok)
						{
							// Since we are not placing an order, we just assume it completed
							${$tick . "buyflag"} = $sellready;
						}

						// CDA is sellready and is no longer trending upwards - time to sell
						if(${$tick . "buyflag"} == $sellready AND ${$tick . "strend"}!=3 AND ${$tick . "mtrend"}!=3)
						{
							// Assume we sell at the current value and if not meeting our sell buffer, we HODL
							$cdabuff = ${$tick . "buyvalue"} * $sellbuffer;
							if($value > $cdabuff)
							{
								${$tick . "sellvalue"} = $value;
								${$tick . "buyflag"} = $selldone;
							}
							else
							{
								printf("%-9s",$key);
								print "Did not meet minimum sell buffer, so HODL!\n";
							}
						}
						// Stop Loss
						$cdastoploss = ${$tick . "buyvalue"} * $stoplossbuffer;
						if($value < $cdastoploss)
						{
							printf("%-9s",$key);
							print "hit the stop loss buffer, so we are selling out\n";
							${$tick . "sellvalue"} = $value;
							${$tick . "buyflag"} = $selldone;							
						}
						// CDA is selldone
						if(${$tick . "buyflag"} == $selldone)
						{
							// Sell Order on CDA placed, do order tracking here to make sure order completes
							// Since we are not placing an order, we just assume it completed
							$q = round((((${$tick . "sellvalue"} - ${$tick . "buyvalue"})/${$tick . "buyvalue"})*100),3);
							$tpc = $q - 0.2;
							$rpc = $rpc + $tpc;
							${$tick . "lasttrade"} = 1;
							${$tick . "lasttpc"} = $tpc;
							${$tick . "buyflag"} = $buyready;
							printf("%-9s",$key);
							print "Sell Done BV:${$tick . "buyvalue"} SV:${$tick . "sellvalue"} TPC:$tpc \n";
							$fh = fopen($tradefile, "a") or die("Cannot open file");
							fwrite($fh, "========================== \n");
							fwrite($fh, "Runtime $run_time \n");
							fwrite($fh, "Sell Done on $key BV:${$tick . "buyvalue"} SV:${$tick . "sellvalue"} TPC:$tpc RPC:$rpc \n");
							fwrite($fh, "========================== \n");
							fclose($fh);
						}
					}
				}
			}
		}
	}
	sleep(5);
}
?>

You need a bigger Window to see all the data :slight_smile:

See what you think.

Moved spread to ltrend, added sellbuffer and stoplossbuffer and changed logic around missing the RSI check. Added BV (the value which the buy was done) plus a CTP (Current Trade Percentage) when there is something we have bought and are waiting for it to sell.

Stay Fishy


#283

Haha! I’ve long past that point, but I’m still very much learning how to trade and automating what I learn as I go. What’s good here and what I’m enjoying most in this entire thread from March til now, is learning how the seasoned professional trader thinks. My game has evolved mightily over the last year and I’ve learned a lot about these markets and “shenanigans” as you like to say, but I know enough to know I don’t know enough and have lots to learn. Automation is not my problem. Solid, consistent trading that weathers a highly-dynamic market is the challenge (and I reckon is so for anyone, let alone one automating the trades).

I’ve been profitable at times and not so profitable at other times and profits die off as either market volatility dies off or new bots come along that toy with price action in a way to trigger one’s bots out of their positions prematurely.

Of late, I’ve been dealing with the sudden and rapid drops in BTC/USDT price with keeping close tabs on the top 25 by volume and tracking Advance/Decline collectively. Kind of a new pattern, kind of not…but you get the point and it speaks wholly to the point you make often about having to constantly improve the scripts to handle more and more scenarios – it’s not just about handling API changes or “code rot”, it’s about handling new patterns of price action effectively and that’s where it all is for me presently.